how to destroy any gameoject which hit the palyer with out using tags
Create a script call FlaggedForDeath.js, with nothing in it, then you attach it to the components that you want to be destroyed, then:
function OnCollisionEnter(collision : Collision)
{
if(collision.collider.GetComponent(FlaggedForDeath))
Destroy(collision.gameObject);
}
Put this on your chacracter:
function OnCollisionEnter (object : Collision) {
Destroy(object.gameObject);
}
Hope this helped!
This is why Layers were invented.
What you need to do is create a Layer (or use one of the pre existing ones) and ignore collisions between player and those layers.
For instance in your case when an object collides with player you don’t care if that object is Terrain or Ground or something. You only care if it’s a Bullet or a Health Kit and so on.
Here are the relevant documentation links :
EDIT : Unity - Manual: Layer-based collision detection
So, you would do something like :
function OnCollisionEnter(collision : Collision)
{
// Where terrainLayerNumber is the numeric value next to the name of the layer that marks your terrain or ground object
if(collision.gameObject.Layer != terrainLayerNumber)
Destroy(collision.gameObject);
}
If you have any more problems post back here.
Hope this helps, Alex
i had found one solution to reduce script i think we can delete preferbs
var chocolate:Transform;
function OnTriggerEnter (myTrigger : Collider) {
DestroyImmediate(chocolate,true);
}
can u help me in deleting preferbs