Hello, i wrote the following script for the fireworks prefab in my game:
var fireWorksID : int; //This Prefab unique Id to determine which fireworks effect is used!
var speedFactor : float = 10.0;
var secondLimit : float = 4.0;
var target : GameObject;
var gameManager : GameObject;
var gameManagerScript : GameManager;
private var speed : float;
var timer : float;
private var hit : RaycastHit;
private var ray : Ray;
function Start () {
target = GameObject.FindWithTag("target");
gameManager = GameObject.FindGameObjectWithTag("GameManager");
gameManagerScript = gameManager.GetComponent("GameManager");
transform.LookAt(target.transform.position);
}
function FixedUpdate () {
if(Input.touchCount == 1) {
ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
Debug.DrawLine(ray.origin,ray.direction * 10);
if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
Explode(1);
}
}
}
function Update () {
timer += Time.deltaTime; //Count in seconds
speed = speedFactor * Time.deltaTime;//this may go in update!
transform.Translate(0, 0, speed);
if (timer >= secondLimit) {//Time-Out
Explode(0); //Call Explosion by time out (status = 0)
}
}
function Explode (status : int){
if (status == 1){//detonated
//Call DetonateFirewors() function on game manager with this object's id, status and position
//gameManagerScript.DetonateFireworks(fireWorksID,transform.position,1);
}
else if (status == 0){//timed out
//Call DetonateFirewors() function on game manager with this object's id, status and position
//gameManagerScript.DetonateFireworks(fireWorksID,transform.position,0);
}
else {
//This one should not be called, but just in case it may be managed as a miss or maybe just "neutral"
//gameManagerScript.DetonateFireworks(fireWorksID,transform.position,0);
Debug.Log("Somehow you managed to make a mistake!");
}
Destroy(this.gameObject);
print("Was destroyed!?");
}
My problem is that when in play mode i touch the prefab all the active clones are destroyed too, i want to destroy only the one i touched, however when they “timeout” they actually destroy only themselves…
I hope you can help me , thanks