B
B
brumper2020-05-18 14:59:12
Unity
brumper, 2020-05-18 14:59:12

Registered a code for collecting coins, and stopped working?

Here is the first code
using UnityEngine;
using System.Collections;

public class Control : MonoBehavior {
public float speed = 10f;

public bool Grounded = false;
public Transform GroundCheck;
public float GroundRadius = 0.2f;
public LayerMask wtfIsGround;

private bool faceRight = true;

Rigidbody2D rig;

void Start() {
rig = GetComponent();

}

void Update () {

Grounded = Physics2D.OverlapCircle(GroundCheck.position, GroundRadius, wtfIsGround);

if (Input.GetKeyDown(KeyCode.Space) && Grounded) {
rig.AddForce(new Vector2(0, 800f));
}

float move;
move = Input.GetAxis("horizontal");
rig.velocity = new Vector2(move * speed, rig.velocity.y);

if (move > 0 && !faceRight)
flip();
else if (move < 0 && faceRight)
flip();
}

void flip() {
faceRight = !faceRight;
transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
}

private void OnTriggerEnter2D (Collider2D collision) {
if (collision.tag.Equals("Money"))
{
MoneyCollect.MoneyCount += 1;
Destroy(collision.gameObject);
}
}
}

Here is the second
using UnityEngine;
using UnityEngine.UI

public class MoneyCollect : MonoBehaviour {
public static int MoneyCount;
private Text MoneyConter;

void Start()
{
MoneyConter = GetComponent();
MoneyCount = 0;
}

void Update ()
{
MoneyConter.text = "X" + MoneyCount;
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
brumper, 2020-05-18
@brumper

in the second script after UI put ;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question