On colision Enter
I use for my fps game this script, for spawning bullet:
var x = Instantiate(proiettile, posizione.position, posizione.rotation);
x.GetComponent.<Rigidbody>().AddForce(x.transform.forward*forza);
I don't now why, with my script, for destroy bullet on collision enter doen't work. I don't know, I don't find nothin about my problem. This's the script for destroy the bullet #pragma strict
function Start () {
}
function Update () {
}
function OncollisionEnter(coll : Collision)
{
Debug.Log("collisione");
Destroy(gameObject);
}
Answer by Developer1212 · Oct 27, 2015 at 09:15 AM
firstly,give 'collision' in 'OncollisionEnter' A capital C.
If that doesn't work , keep the capital C and write this:
function OnCollisionEnter (theCollision : Collision) { //the collision function.
if(theCollision.gameObject.name == "Your Object name here") { //if your bullet collides with whatever your object is called.
Debug.Log("Collision");//Write 'Collision'
Destroy(gameObject);//destroy self
}
}//Copy and paste this and rename "Your Object name here" for each different object that destroys the bullet.
You need an if statement inside the OnCollisionEnter() function. This should work!
yes, but this script doesn't work, it is possible for the high speed? If I try to use time step?
Your answer
![](https://koobas.hobune.stream/wayback/20220612042642im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
MY effect dont destroy 0 Answers
How do I define the direction and speed of a projectile separately? (JS) 0 Answers
My bullet won't go forward? Please check my script and advise me 2 Answers
Player not deleting 2 Answers
Deleting a bullet 3 Answers