- Home /
Question by
mwozniak93 · Apr 02, 2015 at 12:32 PM ·
instantiatedestroy-clones
Destroy Instiantated GameObject on Collision2D
hi! I am trying to destory instianitated gameobject. I can do that when I isntanitate it, and then destroy it after 2 seconds, but if I want to destroy it on collision it desnt do anything it somehow sees Clone as empty gameobject.
using UnityEngine;
using System.Collections;
public class FireUp : MonoBehaviour {
public GameObject hero;
bool fired = false;
public float currentDir;
float energyShootSpeed;
public GameObject energyShoot ;
public GameObject fireball;
public bool bIsColliding ;
GameObject Clone;
void OnCollisionEnter2D (Collision2D col){
Debug.Log ("Clone on Coll Enter : " + Clone);
Destroy (Clone); ---> Here it is empty even if I instainiatate it.
}
void FireLeft (){
float timer = Time.time;
if (currentDir > 0) {
energyShootSpeed = 555f;
}
else if(currentDir<0){
energyShootSpeed = -555f;
}
Vector3 pos = new Vector3(hero.transform.rigidbody2D.position.x,hero.transform.rigidbody2D.position.y+1, hero.transform.position.z-0.6f );
fired = true;
Clone = Instantiate(gameObject,pos,transform.rotation) as GameObject;
Debug.Log ("Clone : " + Clone); ---> Not empty , instance successfully created...
Destroy (Clone, 2f);
Clone.particleSystem.enableEmission = true;
}
}
}
Comment
Hello! Does Debug.Log() show empty gameobject (null) too?
Debug.Log ("Clone on Coll Enter : " + Clone);
Your answer
