Hello !
I have a little problem on my game right now, i’m trying to add a raycast shooter and here is my code :
void Update () {
// If the player is shooting
if (Input.GetButtonDown ("Fire1")) {
source.PlayOneShot(shotSound); // Play a sound
StartCoroutine("shootAnimation"); // Play the animation
Shoot (); // And call the shoot function
}
}
void Shoot () {
RaycastHit hit;
if (Physics.Raycast (camera.position, camera.forward, out hit, weaponRange)) {
Debug.Log ("hit" + hit.transform.name);
}
}
the problem is that i never have any log in my console about what the raycast hit. All the object do have a box collider (3d obviously), but it still don’t works. I tried moving my camera (wich is in the middle of my character that don’t have box collider but only a character controller), and even OUTSIDE of him, it do not work… so i’m actually clueless about what to do haha !
I know it’s a beginner problem but thank by advance for your help !