using System.Collections; using System.Collections.Generic; using UnityEngine; public class ButtonSphereInstantiation : MonoBehaviour { public GameObject spherePrefab; // Reference to the prefab of the sphere public string particle; private ButtonManager buttonManager; public Transform positionToInstantiate; void Start() { buttonManager = GameObject.Find("ButtonManager").GetComponent(); } public void OnButtonPress() { PressButton(); } public void PressButton() { // Check if the prefab is assigned if (spherePrefab != null && buttonManager.isEnableSpawn()) { if (particle == "Proton") { // Instantiate the sphere at the position of the button with no rotation Instantiate(spherePrefab, positionToInstantiate.position, Quaternion.identity); } else if (particle == "Neutron") { // Instantiate the sphere at the position of the button with no rotation Instantiate(spherePrefab, positionToInstantiate.position, Quaternion.identity); } else if (particle == "Electron") { // Instantiate the sphere at the position of the button with no rotation Instantiate(spherePrefab, positionToInstantiate.position, Quaternion.identity); } buttonManager.setEnableSpawn(false); } else { Debug.Log("Sphere prefab is not assigned!"); } } }