- Home /
unity is not responding
i know that this is probably not the place for this question but didnt know where else to put it. i have a very simple script that i am running
var speed : int = 10;
function Update () {
if(transform.rotation.eulerAngles.y <= 190
&& transform.rotation.eulerAngles.y >= 170 && Input.GetKey("d"))
{
transform.rotation.eulerAngles.y = 0;
}
if(transform.rotation.eulerAngles.y == 0 && Input.GetKey("a"))
{
transform.rotation.eulerAngles.y = 180;
}
if(Input.GetKey("d"))
{
transform.Translate(speed * Time.deltaTime, 0, 0);
}
if(Input.GetKey("a"))
{
transform.Translate(speed * Time.deltaTime, 0, 0);
}
if(Input.GetKeyUp("space"))
{
rigidbody.AddForce(0, jump, 0);
}
}
when i add
if(Input.GetKeyUp("space"))
{
rigidbody.AddForce(0, 10, 0);
}
it plays fine until i try and use that bit of script. so all the movement and rotation works but when i try to jump unity stops responding. anyone know why? is it my computer or unity?
Answer by POLYGAMe · Feb 22, 2014 at 09:00 AM
You already have the jump code in the example above, so no need to add it again. That will confuse Unity, having it twice. Also, the variable "jump" has not been declared, so you'll get an error. Plus it might pay not to mix using direct transform translation with physics functions such as add force. I'm not sure but setting it's y axis movement to 0 with transform.Translate then adjusting the rigidbody y velocity with Add Force is bound to cause some odd behaviour.
Your answer
Follow this Question
Related Questions
Jump Code Not Working (2D C#) 2 Answers
In air movement troubles. 1 Answer
how to stop the camera to follow the player on his jump movement ? 2 Answers
Jet-Pack Script 1 Answer
isGrounded is always false, even with gravity, how do you fix that? 1 Answer