Scripting problem

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. :slight_smile:

hello, i dont use javascript but a few points,

is this script on a gameobject in the scene?

try using on keyup because on key down could be getting called multiple time before you release the key as the update function loops fast.

also try to get it working in one script before splitting them so you can locate the problem easier.

Your scripts work fine for me, so the problem seems to be with how your objects are set up in your scene.
Did you perhaps forget to assign the GameObject to your TheSystem variable in the Inspector?