So what I want to do is when the ball touches the ground it can jump, when not it can’t. I wrote this script and I don’t know what is the problem. I get - Assets/Move.js(36,33): BCE0043: Unexpected token: collision.
My scrip:
var forse : float;
var maxSpeed : float;
var jumpforse :float;
var CanJump = true;
function Start () {
}
function Update () {
if(Input.GetKey(KeyCode.W)) {
rigidbody.AddForce (Vector3.forward * forse);
rigidbody.useGravity = true;
}
if(Input.GetKey (KeyCode.S)) {
rigidbody.AddForce (Vector3.back * forse);
rigidbody.useGravity = true;
}
if(Input.GetKey (KeyCode.A)) {
rigidbody.AddForce (Vector3.left * forse);
rigidbody.useGravity = true;
}
if(Input.GetKey (KeyCode.D)) {
rigidbody.AddForce (Vector3.right * forse);
rigidbody.useGravity = true;
}
if(rigidbody.velocity.magnitude > maxSpeed){
rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
}
if(Input.GetButtonDown ("Jump"))
{
OnCollisionStay(collision : Collision);
}
}
function OnCollisionStay (collision : Collision)
{
if(collision.gameObject.name == “Terrain” && CanJump == true) {
rigidbody.AddForce (Vector3.up * jumpforse);
rigidbody.useGravity = true;
}
else {
CanJump = false;
}
}