Hi, I am having an issue with an OnPress() for my mobile game. I am sure it is just from my lack of understanding of how the touch functions work with NGUI. If anyone could help clarify or point out what my mistake might be it would be appreciated.
So pretty much I have two scripts, Button.js and ControlCenter.js. When the NGUI button is pressed I am setting the boolean <nguiTouched = true> (via Button.js) which lives in the ControlCenter.js. This is working how I would expect except for when the button is released the part of the ControlCenter Update function, marked with **, is getting processed and saving the location of the touch release.
The block of code marked should not be getting read since it is inside of the (!nguiTouched) conditional unless I am not understanding how the OnPress() function is called. Am I not using this function properly or is there another function I should be using here?
Thanks in advance,
Button.js
var controlCenter: ControlCenter;
private var pressed: boolean = false; //is this button bieng pressed?
function OnPress()
{
if(!pressed)
{
pressed = true;
controlCenter.nguiTouched = true;
}
else
{
pressed = false;
controlCenter.nguiTouched = false;
}
}
ControlCenter.js
var nguiTouched: boolean = false;
function Update ()
{
if(!nguiTouched)
{
if(Input.touchCount > 0) //if the user presses the screen...
{
var touch: Touch = Input.touches[0];
touchTime += Time.deltaTime; //to avoid accidental presses
**if(needInitialTouchLoc) //get the loc of the initial touch position **
**{ **
** initialTouchLoc = Input.GetTouch(0).position; **
** needInitialTouchLoc = false; **
** print("initialTouchLoc: " + initialTouchLoc); **
**} **
if(other parameters)
{
do other stuff....
}
}
}
}