Hi,
I want to destroy prefab object on mouse touch event.If am using
Destroy(gameObject),it kills all object.but i need to kill only particular object when mouse click on that object…
how to find the gameobject is in out of camera view through script…i need to destroy all gameobject out of camera focus…
Thanks
Well, you could make a destroy function in a script you associate with each of the instances of the object, and then Call it with a Sendmessage Call from a gamecontrollerobject or what you use to control the game overall. This way you are sure the obejcts just destroy themselves. But I guess there are as many approaches to this drill as there are unity users.
Regarding your second question, I would make a box collider that acts like a killzone that is equal to the camara view in size. And the have a onCollisionExit statement that kills the exiting colliders. There may be a smarter way to kill objects that are not in view, though, so this is Just my humble suggestion
Good luck
/Chris
Thanks for reply.
How to associate instance and destroy function…
am using the below script for create instances.just attached this script to empty game object
var objPrefab: Transform;
function BeeCreate(){
var point=Vector3(Random.Range(82,79),Random.Range(22,15),Random.Range(-10,-7));
Instantiate(objPrefab,point,Quaternion.identity);
}
function Awake(){
InvokeRepeating(“BeeCreate”,delay,stepTime);
}
//every 5 sec one instance is creating…
am new to unity…How to use Sendmessage function.am not using any controller…
Thanks
I use an empty object with an attached script as my masterscript, to make sure everything is executed in the right order. Here I maintain central variables, arrays and functions that are used by the other components or objects in the game. This is not needed but it appeals to me to have one central masterscript. At least I have a feeling that I am in charge 
This is usually where I work with the touch events and from here I communicate with the other objects, sometimes w. The Sendmessage function.
This function can execute a function on scripts attached to the receiving objects. it should come in handy in your example
/Chris
/Chris
Thanks for reply
Sorry.I tried.but i didnt get what i expected…
i created prefab for the bird(applied box collider,rigibody).
This prefab i attached to empty gameobject through script.
how to destroy prefab when touch event.
Touch script is attached to prefab.
can u give sample code and where i have to give that script…
Hi. Make sure to create a script, beescript for instance, and associate it to the prefab. In that script have a kill function that destroys the instantiated object.
Read about destroy here
/Chris
Hi chris,
Thank you so much for help…Now Its working so good.
Thanks