How do I make a script to make a series of cubes that when clicked, they are deleted and summon a prefab in their place, then the prefab despawns?
I am fairly new to Unity and I am trying to make an script that deletes a basic textured Game Object cube that when clicked by the mouse, it deletes ONLY the cube that was clicked, then spawns a prefab cube filled with smaller cubes that despawns five seconds after it has spawned. I have searched for many codes and help for this issue, and no luck. Also, do I attach the script to the cubes themselves, or the FPS controller camera?
Here is an outdated script I found. I have no idea what's wrong with it:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Idunno : MonoBehaviour { // Use this for initialization void Start() {
}
void Update()
{ if (Input.GetButtonDown("0")) { Raycast ray = Camera.main.ScreenPointToRay(Input.MousePosition); Raycasthit hit;
if (Physics.Raycast(ray, hit))
{
Destroy(GameObject.Find("hit.name"));
}
}
}