Support => NGUI 3 Support => Topic started by: xikky on June 18, 2013, 04:54:53 AM
Title: How to check if an NGUI object is hit or not?
Post by: xikky on June 18, 2013, 04:54:53 AM
In order to check whether my "input touch script" should be executed or not, every FixedUpdate I'm checking the UICamera.hoveredObject result. I want that my script is only executed when UICamera.hoveredObject is null.
This is a simplified example of my code:
function FixedUpdate (){
if(Input.touchCount==1){
if(Input.GetTouch(0).phase== TouchPhase.Began){
if(nguiCamera.hoveredObject!=null)
word += nguiCamera.hoveredObject.ToString();
else
word +="null";
}
}
}
the string 'word' is displayed OnGUI.
The problem is that UICamera.hoveredObject result is a frame late.
So if I touch over a non NGUI object, word = null, then touch over NGUI object, word = null, then touch over NGUI object, word = not null, then touch over non NGUI object, word = not null, then touch over non NGUI object, word = null,
What am I doing wrong here? or is there another better solution to identify when an NGUI object is hit or not?
Title: Re: How to check if an NGUI object is hit or not?
Post by: ArenMook on June 18, 2013, 12:04:40 PM
NGUI also updates its hovered object in FixedUpdate, so you have to adjust the script execution order to make yours execute right after it.
Title: Re: How to check if an NGUI object is hit or not?
Post by: xikky on June 18, 2013, 12:40:02 PM
Oh I see, I thought since UICamera is inside the plugins folder, UICamera.hoveredObject would be executed before my javascript files.
I fixed the script execution order by placing my "input touch script" at the bottom of all. When running the game using Unity Remote, hoveredObject works as expected. But when I build my game on android, again the hoveredObject works 1 frame late.
Am I missing something else? :/
Title: Re: How to check if an NGUI object is hit or not?
Post by: ArenMook on June 18, 2013, 02:13:28 PM
I'm not sure how the script order works on android. If you can't get it to work, you can always move your logic from FixedUpdate into regular Update. I'm not sure why you have it in FixedUpdate anyway. FixedUpdate is for physics.