Hi everyone. I’m trying to do something very simple, when my “player” is on the ground, a text is set to true, but as you can see it does not work…
public class PlayerController : MonoBehaviour {
Rigidbody2D rb;
public float speed;
public Text bottomText;
public Text topText;
bool isOnGround;
bool isOnTop;
// Use this for initialization
void Start () {
rb = gameObject.GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("right")) {
rb.velocity = new Vector2 (speed, 0);
}
if (Input.GetKeyDown ("left")) {
rb.velocity = new Vector2 (-speed, 0);
}
if (Input.GetKeyDown ("up")) {
rb.velocity = new Vector2 (0, speed);
}
bottomText.text = isOnGround.ToString();
topText.text = isOnTop.ToString();
}
void OnCollisionEnter(Collision col){
if(col.gameObject.tag == "ground"){
isOnGround = true;
}
if(col.gameObject.tag == "top"){
isOnTop = true;
}
}
}