Raycast 3d not casting anything

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 !

Try using DrawRay to see if that helps debug the problem. For example, does it show that an object is actually in the line of fire?

I just tried it and it does show that an object is in the line of fire (it goes through it), but still no log :frowning:

Ok i’m actually a huge idiot, because i just desactivated all debug messages in my console so OBVIOUSLY they did’nt show up. Except this everything works fine. So sorry for this, it was really the most dumb problem i encountered on unity so far haha…

Nice. Glad to hear you figured it out. :slight_smile: