This one might be new and harder to figure out, not the best with c# but i try. So, the situation is i have 3 Buttons, each with the same script and that script contains a public var [public GameObject ItemToSpawn;] This allows me to drag and drop a prefab onto the button to select which object i would like to spawn from said button. I could go the long way and make 3 different scripts and 3 different buttons but there are many more objects that i would like to spawn in. Code i have currently:
public GameObject ItemToSpawn;
public float yCoord = 0;
public float zCoord = 0;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; // raycast things
if (Physics.Raycast(ray, out hit)) // Checks to see if mouse clicked button
{
if (hit.transform.name == "SpawnButton")
{
Instantiate(this.ItemToSpawn, new Vector3(0, yCoord, zCoord),Quaternion.identity); //Spawns in item at users location provided
}
}
}
}
Thanks in advance! (Also this is reupload because posted in wrong location)