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.