Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Instantiate keep on cloning my object - How can I stop it!?

$
0
0
I'm trying to make a destructible object by using 2 codes that I learned from a tutorial. http://gamedevelopment.tutsplus.com/tutorials/how-to-make-an-object-shatter-into-smaller-fragments-in-unity--gamedev-11795 At first, it was somewhat working. But after I added a few more codes of mine in it, it got messed up. It keeps on cloning and made my whole game lagging. using UnityEngine; using System.Collections; public class Destroy : MonoBehaviour { public GameObject remains; private PlayerInteract securityCheck; public bool destroyed = false; // Use this for initialization void Start() { destroyed = false; securityCheck = GameObject.Find("Player").GetComponent(); } // Update is called once per frame void Update() { if (securityCheck.doorOpen == true) { StartCoroutine(BOMB()); destroyed = true; } } IEnumerator BOMB() { yield return new WaitForSeconds(1); Instantiate(remains, transform.position, transform.rotation); Destroy(gameObject); } } This is the 2nd code. It did destroyed my original object but didn't do anything with the clones. public class SelfDestruct : MonoBehaviour { private Destroy destroy; public ParticleSystem explode; // Use this for initialization void Start () { destroy = GameObject.Find("Cube fragment").GetComponent(); } // Update is called once per frame void LateUpdate () { if (destroy.destroyed == true) { ParticleBoom(); StartCoroutine(Destroy()); Destroy(explode); } } IEnumerator Destroy() { yield return new WaitForSeconds(2); Destroy(gameObject); Debug.Log("Bang Bang Bang"); } void ParticleBoom() { explode = (ParticleSystem)Instantiate(explode, transform.position, Quaternion.identity); } } And my explode particle system isn't working properly either, it keeps on cloning and exploding, so I had to destroy its "explode".

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>