- Home /
I dont know whats wrong with my script
var Playerstate : float; var PlayerAnimSec : GameObject;
function Update () ) PlayerStateController(); PlayerAnims(); around here is were it is wrong )
function PlayerStateController() ( if ((input.GetAxis("Vertical")!=0 ||input.Get Axis("Horizontal")!=0) ( if (input.Getbutton("Sprint")) ( Playerstate = 2; ) else ( Playerstate = 1; ) ) else ( Playerstate = 0; )
)
function PlayerAnims() ( if (Playerstate == 0) ( PlayerAnimSec.animation.CrossFade("Idle Animation", 0.4); ) ( else if (Playerstate == 1) ( PlayerAnimSec.animation.CrossFade("Walking Animation", 0.4); ) else if (Playerstate == 2) ( PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4); )
Formatted code (looks like there are no curly braces, code is as in the above original post) :
var Playerstate : float; var PlayerAnimSec : GameObject;
function Update () ) PlayerStateController(); PlayerAnims(); around here is were it is wrong )
function PlayerStateController() ( if ((input.GetAxis("Vertical")!=0 ||input.Get Axis("Horizontal")!=0) ( if (input.Getbutton("Sprint")) ( Playerstate = 2; ) else ( Playerstate = 1; ) ) else ( Playerstate = 0; ) )
function PlayerAnims() ( if (Playerstate == 0) ( PlayerAnimSec.animation.CrossFade("Idle Animation", 0.4); ) ( else if (Playerstate == 1) ( PlayerAnimSec.animation.CrossFade("Walking Animation", 0.4); ) else if (Playerstate == 2) ( PlayerAnimSec.animation.CrossFade("Sprint Animation", 0.4); )
Please edit and format your code with the 101/010 button Also tell us what you think is wrong. Was there an error message?
To help the new user and with their karma, I have edited the question. TopazX , as Dave said, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
And tell us what you think is wrong, what is happening?
Just before starting to edit, I see you have no curly braces { or }
Please check your code, and post the current code you are using.
Answer by chelnok · Nov 21, 2012 at 05:23 AM
Looks like you are using parentheses when you should use curly brackets.
You code: function PlayerStateController() ( if ... )
Should be: function PlayerStateController() { if ... }
Example for correct way to use them:
function Update ()
{
if (something == 1)
{
doSomething();
}
else
{
doSomethinElse();
}
}
function doSomething()
{
print("Learing to fly");
}
You might want to learn some basics of coding.
Here is some basics about javascript in Unity: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)