- Home /
What is the problem ???? Assets/Move.js(36,33): BCE0043: Unexpected token: collision.
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;
}
}
Answer by KellyThomas · Dec 14, 2013 at 03:20 PM
This section is causing the error:
if(Input.GetButtonDown ("Jump"))
{
OnCollisionStay(collision : Collision);
}
If you wanted to call OnCollisionStay()
and pass a varaible call collsion you would do it like this:
OnCollisionStay(collision); //no need to define the variable type
However (as far as the posted code reveals) you don't currently have a collision
variable within scope.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124141im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy being rude and not facing me 2 Answers
Gravity on object not working correctly 1 Answer
Object reference not set to an instance of an object 1 Answer
Strategy camera problems. 0 Answers
Move Capsule Collider to Model 1 Answer