In my Android game I have a script with this code: Code (csharp): #pragma strict public var Collider1: Collider; public var Collider2: Collider; public var Test1Active: boolean = false; public var Test2Active: boolean = false; function Update () { var sceneCams = Camera.allCameras; for(var thisCam: Camera in sceneCams) { DoCameraRayCasts(thisCam); } } function DoCameraRayCasts(camReference: Camera) { var ray: Ray = camReference.ScreenPointToRay (Input.mousePosition); var hit: RaycastHit; if (Collider1.Raycast(ray, hit, Mathf.Infinity)) { Test1Active = true; } if(Collider2.Raycast(ray, hit, Mathf.Infinity)) { Test2Active = true; } } When Collider1 is hit, Test1Active becomes true and when Collider2 is hit, Test2Active becomes true. But sometimes Test1Active becomes true when Collider2 is hit. Is there something wrong with this code? (Somewhere else in the script Test1Active and Test2Active are set to false again before you can hit a collider).
No, it's not possible to hit both at once. There's a lot of space between them. I start to think that this code is not wrong but that something else in the script goes wrong. But the code above is the only part of the script where Test1Active = true.
Or perform a scene raycast rather than just casting against those objects. Off the top of my head... Code (csharp): bool didHit = Physics.Raycast(ray, hit); if (didHit) { if (hit.collider == Collider1) { // Blah } else if (hit.collider = Collider2) { // Blah } } herbie, the difference is that you're checking a rays against specific colliders, which I'm pretty sure just returns whether an intersection exists, whereas the above casts a ray into the whole scene and then checks the collected hit info to see what was hit. Edit: In that case it could be worth showing the rest of the script. Nothing seems broken in what you've shown above.