- Home /
Private Variable didn't work?
Hello guys, i have animated object in scene. Object have 2 animation's. I animating them by private variable. All seems gonna be ok before i duplecate object. When i duplicate object and start interact with one of them the first animation going good but if i then interact with second he is playing second animation(must playing 1st too). I am using variable
private var _Activated : boolean;
if(Physics.Raycast(ray.origin, ray.direction,hit, 5.0)){
if(hit.collider.gameObject.tag==obj && _Activated == false){
currentObj = hit.collider.gameObject;
ObjectControl(Anim1Sound,true,anim1,currentObj);
}
else if( _Activated == true)
{
currentObj = hit.collider.gameObject;
ObjectControl(Anim2Sound,false,anim2,currentObj);
}
}
What should i do with my variable? or i need another method?
Thank you!
Formatting your code right is very important, or people won't bother to read it.
what is in your variable "obj"? is it a string or is it something else? You're trying to compare it to a string (tag) but if obj is a gameObject, you're never going to satisfy either conditions.
Answer by zmar0519 · Jun 10, 2011 at 06:45 PM
your variable isn't set, so it is neither true nor false. try adding = true
or = false
to your code and see if that helps.
@$$anonymous$$ike 3, but you could have an uninitialized bool. Couldn't you?
Nope, they're always guaranteed to be initialized with a default value at the very least
Sorry to keep bothering you about this, but I'm interested in learning a little more. This code:
void Start () {
bool isTrue;
if(isTrue)
Debug.Log("Yes it is true");
}
throws a CS0165, use of an unassigned local variable exception.