- Home /
Temporary boost
In my 2D vertical platformgame i want to give my player a temporary jump boost. im thinking something like.
if(hit.gameObject.tag == "Boost")
{
**var jumpheight =*2.0;**
yield.WaitForSeconds(5.0) destroy()
But im not sure how to put this in code.
Comment
Answer by Piflik · Jan 05, 2013 at 04:11 PM
Something like this should work:
public var jumpHeight : float = 5.0;
public var jumpTimer : float = 2.5;
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit. gameObject.tag == "Boost") {
jumpHeight *= 2.0;
Invoke("ResetJump", jumpTimer);
}
}
function ResetJump() {
jumpHeight *= 0.5;
}
Great! Is it possible to make this outside of the controller script? maybe by making jumpheight a public static var and acces it from an external script. Now my console sees jumpheight as an unknown identifier.
No need to make it static. Public variables can be accessed by other scripts with GameObject.GetComponent(Scriptname).Variablename.
I see the problem. all the jumping related variables are contained in a class. so i cant seem to acces them from outside of the class. Do you know how i might solve this.