Hey!
I’ve recently taken an interested in 2D game creation, however I’m struggling a bit when it comes to changing the boolean of another script when the main character collides with the ground.
At the moment, the character is correctly triggering the collision and changing the boolean when it’s coming from the GroundCheck.cs script.
However whenever I try to change the boolean in the PlayerController.cs script it just doesn’t work.
My script is as follows, any help would be appreciated. I’m racking my head around it, and I just want to understand this problem before I progress.
using UnityEngine;
using System.Collections;
public class GroundCheck : MonoBehaviour {
public PlayerController player;
// public bool grounded;
void start()
{
player = gameObject.GetComponent<PlayerController> ();
}
void OnTriggerEnter2D(Collider2D other)
{
player.grounded = true;
}
void OnTriggerExit2D(Collider2D coll)
{
player.grounded = false;
}
}
I’ve also tried both GetComponent and GetComponentInParent.
Thanks in advance!