2 Raycast hits on double tap input- why?

Hi, all,

I’m getting a strange result with this raycast / object replacement script. It seems the double tap is sending two raycasts, triggering the replacement object as well. Any ideas why?

Thanks,

G

var deadReplacementPosition : Vector3;
var deadReplacementRotation : Quaternion;          
var RandomObjects : Rigidbody[];
var hit : RaycastHit;
var dieSound : AudioClip;
var initialDelay = 1.0;
var fadeSpeed = 1.0;
var explosion : Transform;
var damagesound : AudioClip;
var myTransform : Transform;

function Awake() {
   myTransform = transform; // this objects transform
}

function Update () {
   for (var evt : iPhoneTouch in iPhoneInput.touches) {
     
     if(iPhoneInput.GetTouch(0).tapCount == 1)  {
         var ray = camera.main.ScreenPointToRay(evt.position);
         if (Physics.Raycast(ray, hit, 1000) ) {
            var hitObject : GameObject = hit.transform.gameObject;
            var hitTransform : Transform = hitObject.transform;
            if ( hitObject.tag == "CRANE" ) {
                      
                       Destroy( hit.collider.gameObject );
                     
                     // Play a dying audio clip
                     if (dieSound) {
                        AudioSource.PlayClipAtPoint(dieSound, transform.position);
                     }
                     
   


    if(RandomObjects){   
    var dead : Rigidbody = Instantiate(RandomObjects[Random.Range(0,RandomObjects.Length)], transform.position, transform.rotation);
      
    }}}}}}

i have never used unity iPhone so forgive me if i am mistaken, but you are using this line

...

if(iPhoneInput.GetTouch(0).tapCount == 1)  {

...

doesn’t that mean that you are looking for single taps?

Hi dbp, thanks for the reply. Yes, I changed that to 1 for testing and still get the same problem with a single tap. It seems that this code has a problem instantiating a replacement object with raycasts. I’m still checking into it.

Thanks,

G

hmm just a guess, but maybe replace the line of code i mentioned with this

if(evt.tapCount == 1)  {

what i think is happening is that you are running through the for loop 2 times, i don’t know which gestures it recognizes, but both times u access iPhoneInput.GetTouch(0) directly, so no matter which gestures you use, if touch 0 is a single tap, it will raycast for each gesture in the list