Hello guys! I have a question - what’s wrong in my code?
I have 2 scripts, one to trigger function and one that is triggered.
First one is a child null object with script
#pragma strict
var TheSystem : Transform;
function Update ()
{
if (Input.GetKeyDown(KeyCode.E))
{
TheSystem.SendMessage("SwitchIt",SendMessageOptions.DontRequireReceiver);
}
}
// TheSystem - is Player, it's dragged in box TheSystem properly
Second one is on a lightswitch, that must be switched
#pragma strict
var SwitchIsUp = true;
function SwitchIt ()
{
if (SwitchIsUp == true)
{
gameObject.animation.Play("SwitchDown");
SwitchIsUp = false;
}
else
{
gameObject.animation.Play("SwitchUp");
SwitchIsUp = true;
}
}
The problem is - nothing happens, and I can’t understand why. There’s no errors niether. I’m a begginer in scripting tbh.
Thank you)
Added:
Btw, if there’s only one script
#pragma strict
var SwitchIsUp = true;
function Update ()
{
if (Input.GetKeyDown(KeyCode.E))
{
if (SwitchIsUp == true)
{
gameObject.animation.Play("SwitchDown");
SwitchIsUp = false;
}
else
{
gameObject.animation.Play("SwitchUp");
SwitchIsUp = true;
}
}
}
Animations are playing.