How do I place a prefab at the place where my player is looking?

The question says it all.

Hi, check this answer:


You can add a Raycast in the player’s camera, and set its hit position as thw spawn point for your prefab. Here is an example:

public float range;
public GameObject prefab;
public Transform playerCam;

void Update(){
  RaycastHit hit;
     if(Physics.Raycast(playerCam.position, playerCam.forward, out hit, range){
       if(hit.transform != null)
          Instantiate(prefab, hit.point, Quaternion.identity);