Question by 
               day_dias · Jul 18, 2017 at 10:52 PM · 
                raycastcollidergameobjectsraycasthit  
              
 
              How can I select 2 different objects using RayCastHit?
Hello,
I need to select an object and wait for user select another one, I'm using RayCast for pick up the GameObjects. When I call the first one with a mousebuttondown it works fine, however if use the same struture to call the second one it looks like the RayCastHit is saving the first one choice and pass throw it. Does anyone know how to fix it or improve my code please I'm getting crazy.
 #pragma strict
 import System.Collections.Generic;
 
 private var ray : Ray;
 private var ray2 : Ray;
 private var hit : RaycastHit;
 private var hit2 : RaycastHit;
 private var paraRaycast: boolean;
 
 var primeiraPorta: boolean;
 var segundaPorta: boolean;
 var esperaSegundaPorta : boolean;
 
 function Start () {
     
 }
 
 function Update () {
     
     if(Input.GetMouseButtonDown(0)) {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit)) {
              if(hit.collider.tag == "portas") {
                 Debug.Log("Primeira Porta");
                 primeiraPorta = true;
 
 
 
                 EscolheSegundaPorta();    
 
             }
         
         }
         
     }
 }
 
     function EscolheSegundaPorta()
  {
      esperaSegundaPorta = false;
      print("Selecione a segunda porta");
 
            if(Input.GetMouseButtonDown(0)) {
         ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
              if(Physics.Raycast(ray2, hit2)) {
                 if(hit2.collider.tag == "portas") {
 
                     esperaSegundaPorta = true;
                     Debug.Log("Segunda Porta");                     
                      }
 
                  }
          }
        
       
 }    
         
 
              
               Comment
              
 
               
              Your answer