- Home /
scripting problem with if statements
i have this script so i can switch between weapons, a sword and a ninja star.
function Update() { var sword = Transform; var star = Tranform;
sword.active = true;
star.active = false;
if(sword.active = true)
{
}
if(sword.active = true)
{
}
}
When i save this i get 5 errors: Assets/my scripts/walker.js(25,21): BCE0044: expecting ), found '='.
Assets/my scripts/walker.js(25,23): BCE0043: Unexpected token: true.
Assets/my scripts/walker.js(28,10): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/my scripts/walker.js(29,24): BCE0044: expecting ), found '='.
Assets/my scripts/walker.js(29,26): BCE0043: Unexpected token: true.
Assets/my scripts/walker.js(32,10): UCE0001: ';' expected. Insert a semicolon at the end.
Can you tell me why i this is happening?
Answer by tertle · Feb 10, 2011 at 02:54 AM
= is an assignment operation
== is a comparison operation
should be
if(sword.active == true)
But the "== true" part is redundant when checking Boolean operation like that. You can just do:
if(sword.active)
will work fine, or if you want to check if false
if(!sword.active)
that is cool, but here is another question. when i have a my script like that the character does not walk awhen the star is false. he only walks when they both are set to true. whats up with that? this is the walking part of my script: var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.forward; var curSpeed = speed Input.GetAxis ("Vertical"); controller.Simple$$anonymous$$ove(forward * curSpeed);
Your answer
Follow this Question
Related Questions
3 java errors on a basic shooting script? 2 Answers
Formatting problems in Script 2 Answers
SwipeControl package error in unity iPhone 1.7 1 Answer
error message for var 1 Answer
Code Not Working. Any Ideas? 2 Answers