I AM CREATING A NUMBER OF CLONES OF THE GAMEOBJECT FOR MY GAME.THE MOTTO OF MY GAME IS TO GENERATE A NUMBER OF THE GAMEOBJECT (CLONE) AND I AM SUCCESSFULLY DOING THIS BUT WHEN I AM TRYING TO DESTROY THE CLONE OF THE GAMEOBJECT ON MOUSE CLICK, MY BASIC GAMEOBJECT IS BEING DESTROYED BUT ORIGINALLY ACCORDING TO ME THE CLONES SHOULD HAVE DESTROYED
public class Ball : MonoBehaviour {
public gamecontroller _gamecontroller;
// Use this for initialization
void Start () {
_gamecontroller = GameObject.FindObjectOfType(typeof(gamecontroller)) as gamecontroller;
}
// Update is called once per frame
void Update () {
}
void OnMouseDown() {
Destroy(transform.gameObject);
}
}
AND THIS CODE HAS BEEN ATTACHED TO THE GAMEOBJECT I M TRYING TO CLONE AND DESTROY
I found some help ages ago for a script to destroy cloned objects and I’m happy to share it with you as I found it can get a little frustrating.
Basically, attach this script to the prefab object and you can set how long it takes before the object is destroyed in the inspector.
#pragma strict
var timeToEnd : float;
function Update ()
{
Destroy(gameObject, timeToEnd);
}
The beauty of this is that you can basically write the parameters you want to destroy the object in, I used this to destroy a laser bolt when it reached the edge of the screen.
#pragma strict
var timeToEnd : float;
function Update ()
{
if (transform.position.x < -8.5f)
{
Destroy(gameObject);
}
else
{
Destroy(gameObject, timeToEnd);
}
}
Please don't SHOUT.
– Huacanachasorry if u r hurt but can u please tell me which word of mine seems u to be shouting I will edit it
– shadab_badarI'm not hurt :) But don't use ALL CAPS... it draws unnecessary attention to your post and makes the text hard to read.
– Huacanachathanks for the suggestion I will keep this in my mind now onwards
– shadab_badar