[Help] onTrigger/Changing bool.

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!

I managed to solve the problem by moving the onTrigger events to the PlayerController.cs. Collision works how I want it to. However I’d still like to work out why it isn’t updating from another script, just so I don’t face the same problem later on.

I don’t just want a fix, I want to find out why it’s not working.

Any help would be great!

Have you put break points in so you can check what’s being passed? Were there any messages in the console? I’m assuming that PlayerContoller is the name of the script with the bool on it