I want users to click on specific game objects and build prefabs at the original game object’s location they just clicked on. I wrote this script to instantiate the prefab, and attached the script to each of those game objects. The problem is, when I click on any game object with that script–every game object with that script attached instantiates a cube, instead of just one at that specific location I selected. Am I missing something?
[SerializeField] private GameObject cubePrefab;
void Update()
{
//if user clicks on the interactable game object
{
Spawn();
}
}
private void Spawn()
{
Instantiate(cubePrefab, transform.position, transform.rotation);
}
Thank you so much. I’ve gone through a ton of Prefab Instantiation posts and videos, and I’m still not getting what the problem is. I feel like I’m missing some important concept here!