When the mouse clicks the Ngui UI in unity, the Rays collide with the scene object, performing other manifestations.
So the question is how to avoid simultaneous triggering,
One principle is that the UI executes the first order.
So let's talk about the main thread execution sequence.
1. Main thread structure
1 public class Gamemain:monobehaviour 2 { 3 void Update () 4 { 5 NGUIManager.Instance.Update (); 6 GameSceneManager.Instance.Update (); 7 .... 8 9
}
2, above can see UI execution priority higher than other logic, we look at the UI logic
public bool Raycasthitui (Vector3 positon) {Vector3 pos = camera.screentoviewportpoint (Positon); if (Pos.x < 0f | | Pos.x & Gt 1f | | Pos.y < 0f | | Pos.y > 1f) return false; Ray Ray = Ui2dcamera.screenpointtoray (inPos), int mask = 1 << 20;float dist = (uicamera.rangedistance > 0f)? Uicamera.rangedistance:ui2dcamera.farclipplane-ui2dcamera.nearclipplane;if (Physics.raycast (Ray, out UiHit, Dist, Mask) return True;return false;}
So the UI event is executed and the logic behind it is not executed!
Performing UI events blocking Ray scene events