Hello!
I just have a problem. I use two scripts - ‘ButtonMovement’ and ‘GroundChecker’. ButtonMovement is assigned to my jump button, and GroundChecker to my Player. The problem is that variable ‘grounded’ doesn’t work in ButtonMovement script [it works in GroundChecker (it shows grounded = true if player hit ground and false if it doesn’t)]. Here are the scripts (I am novice programmer ;D):
ButtonMovement:
http://wklej.org/id/1750647/
GroundChecker:
http://wklej.org/id/1750650/
You’re creating a new GroundChecker (aren’t you getting a warning for that?) inside ButtonMovement instead of using GetComponent<> to access it.
Change the top line:
GroundChecker check = new GroundChecker ();
to:
GroundChecker check;
And change your Start() function:
void Start () {
playerRigidbody = playerObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator> ();
}
to:
void Start () {
playerRigidbody = playerObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator> ();
check = gameObject.GetComponent<GroundChecker>();
}
Nothing is going to work properly while you have errors in the console. You need to resolve those.
Now there are no errors, but still doesn’t work.