AtomCraft-2.28/AtomURP-main/Assets/Scripts/InstantiateSphere.cs
MinaMaddahi c30f28b574 Electron updates
New Repo changes
2024-03-13 18:51:15 +01:00

52 lines
1.6 KiB
C#

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<ButtonManager>();
}
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!");
}
}
}