I have a goal to create a bullet hole in the place where the ray hit, for this purpose I made a material, put a picture of a bullet hole on it, and sent the material itself to plane, and made it a prefab. I created a variable to which I threw this prefab:
public GameObject shootPF;
and I create it in the Instantiate() method:
if (Input.GetMouseButtonDown(0))
{
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
GameObject hitObject = hit.transform.gameObject;
EnemyCodeD enemy = hitObject.GetComponent<EnemyCodeD>();
if (enemy != null)
{
enemy.Hit();
}
else
{
Debug.Log(shootPF);
Instantiate(
shootPF,
hit.point + (hit.normal * .01f),
Quaternion.FromToRotation(
Vector3.up,
hit.normal
)
);
}
}
The problem is that for some reason shootPF is null, although I passed everything in the inspector and there should be no problem with it. Why is that?
Debug.Log("ShootPF", Instantiate(...))
this should log a message in the console and when you click on it (still while in playmode!) it should select the cloned bullet decal. \$\endgroup\$