Hello. I’ve built a cube that creates clones , when you press the spacebar.I have the following code programmed:
using UnityEngine;
using System.Collections;
public class kaputt : MonoBehaviour {
void Start () {
}
void Update () {
if(Input.GetKey(KeyCode.Space)) {
GameObject cube1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube1.AddComponent<Rigidbody>();
cube1.transform.position = new Vector3(0, 5, 0);
}
}
void OnBecameInvisible() {
Destroy (gameObject);
}
}
How can I clones that passed " OnBecameInvisible ( ) " so that they destroy themselves when the camera no longer has in mind ?
Many thanks