- Home /
 
Make tagged objects explode with ray cast?
Basically, I am trying to make certain objects tagged Barrels explode when hit with a ray cast. I am getting the compiling error of BCE0077: It is not possible to invoke an expression of type 'String'.
Here is my script:
 // Prints the name of the object camera is directly looking at
 var explosion : Transform;
 
 function Update () {
     if (Input.GetButtonDown("Fire1"))
         // Get the ray going through the center of the screen
         var ray : Ray = camera.ViewportPointToRay (Vector3(0.5,0.5,0));
 
     // Do a raycast
     var hit : RaycastHit;
 
     if (Physics.Raycast (ray, hit))
         print ("I'm looking at " + hit.transform.name);
         
    if (Physics.Raycast (ray, hit))
          Debug.DrawLine (ray.origin, hit.point);
 
    if (Physics.Raycast (ray, hit))
          Destroy(hit.collider.gameObject);
 
    if (hit.collider.gameObject.tag ("Barrels")){
          Instantiate (explosion, transform.position, transform.rotation);
    }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by AlucardJay · Jul 25, 2012 at 08:26 AM
 if (hit.collider.gameObject.tag ("Barrels")){
 
               change this to :
 if ( hit.collider.gameObject.tag == "Barrels" )
 
               I also re-formatted your code =]
Your answer
 
             Follow this Question
Related Questions
Raycast on touch 3 Answers
Bug/Error in script CollectPapers 0 Answers
Enemy Raycasting Damage 0 Answers
gameObject tag 2 Answers