I have touch detected now how do I make it talk to my movement script ?

Ok so I have a 2.5D project I am messing around with. Now that I have the IOS/Android licenses I would like to make builds to test out on my phone. So I need to set up touch controls.

Here is a screenshot:
![alt text][1]
[1]: http://desmond.imageshack.us/Himg17/scaled.php?server=17&filename=examplead.jpg&res=medium

Pretty simple set up that I need. I dont need anything to move/snap back I just need to know when the button is pressed.

Now I have code that lets me detect when the button is pressed and it registers on the unity remote fine. I have read through it numerous times so i understand it well.
(This is attached to GUITexture)

var guiJumpButton : GUITexture;
var touchJump  : boolean = false;
function Update()
{
 if(Input.touchCount > 0)
	{
	 for(var i : int = 0; i < Input.touchCount; i++)
		{
		 var touch : Touch = Input.GetTouch(i);
			if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
				{
				 Debug.Log("Can Jump");
				 touchJump = true;
				}
			else touchJump = false;
			//Debug.Log ("No Jump");
		}
	}
}

Now what I thought I would do is be cool and when the button is pressed change a boolean to true, then I would access that boolean from my movement control script.(This is part of movement script attached to my character)

//Access to touch script
	var accessToTouchControls = GetComponent(Script_Touch_Controls);
	var accTouchJump = accessToTouchControls.touchJump;
   
//Allow Character to jump 
	if ( accTouchJump && ( controller.isGrounded ))
		{
			velocity.y = jumpHeight;
		}

however when I do this I get a “Object reference not set to an instance of an object”. So is my syntax bad or is this a completely wrong way to approach this ?

Any advice on how to properly get the buttons to talk correctly with my movement script would be much appreciated.

I’m guessing Script_Touch_Controls is not found? Make sure the Script_Touch_Controls script is on the same object, or you’ll have to find the object that it’s on.

It’s way better to setup your references at building time. Just offer a public variable of your other script type and assign the other object to the variable in the inspector via drag&drop:

var jumpcontrolScript : Script_Touch_Controls; // assign in the inspector
function Update()
{
    if( jumpcontrolScript.touchJump && controller.isGrounded )
    {
        // Do something
    }
}

btw. It’s better to create more reusable code. You could use the Script_Touch_Controls script on multiple touch buttons. For this you should name your “output variable” something more common like .isPressed.

The assignment which button controls what can be done via drag & drop in the inspector.