- Home /
 
               Question by 
               ninjustice · Mar 27, 2015 at 04:57 PM · 
                raycast  
              
 
              Noob Raycast question
Hey, I was just wondering why there was nothing in the console when I click on a box with the tag, "Enemy".
 using UnityEngine;
 using System.Collections;
 
 public class fireScript : MonoBehaviour {
 
 
 
     // Use this for initialization
     void Start ()
     {
 
     }
     
     // Update is called once per frame
     void Update ()
     {
         Camera cam = Camera.main;
         if (Input.GetButton ("Fire1"))
         {
             RaycastHit hit;
             if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit))
             {
                 if (hit.collider.tag == "Enemy")
                 {
                     Debug.Log("OUCH!");
                 }
             }
         }
     }
 }
 
               Comment
              
 
               
              Probably because cam.transform.forward has a length of 1, which might be too short. Look up the different overloads of Physics.Raycast or just multiply it by some larger value.
Your answer
 
 
             Follow this Question
Related Questions
Unity Character Controller messing up. 0 Answers
Follow mouse until mouseclick 0 Answers
hit.gameObject.AddComponent not working 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                