I want to create an auxiliary function for creating a decal.
I have this class which is not attached to any Game Object.
public class AuxiliaryFunctions : MonoBehaviour
{
[SerializeField] private GameObject gunHole;
private GameObject decal;
public void CreateGunDecal(RaycastHit hit)
{
decal = Instantiate(gunHole, hit.point, Quaternion.LookRotation(hit.normal));
// Avoid z conflict.
decal.transform.position += decal.transform.forward * 0.01f;
}
}
I attached a prefab for gunHole via Unity interface.
Then I call the CreateGunDecal in another script which is attached to Player.
if (hit.collider.tag == "Level")
{
auxiliary.CreateGunDecal(hit);
}
After running I got this error trying to Instantiate a decal.
> ArgumentException: The Object you want to instantiate is null.
I checked other topics of the same error and tried different approaches but could not find out what was wrong in my case.
↧