- Home /
How add and mark next object?
Hi, how add and mark next object? please, i dont know how rite. Code: public class DestroyByContact2 : MonoBehaviour {
public AudioClip impact;
AudioSource audioSource;
public GameObject explosion; // drag your explosion prefab here
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Asteroids" ) {
GameObject expl = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;
audioSource.PlayOneShot(impact, 0.7F);
Destroy(collision.gameObject); // destroy the grenade
Destroy(expl, 5); // delete the explosion after 2 seconds
}
}
}
$$anonymous$$ay I ask what do you mean from "add and mark next object"?
touche ahah
It appears this is a grenade script that destroys the objects thrown or shot searches for objects named Asteroid, when collision happens. If the object is an asteroid, it destroys the grenade and then adds an explosion effect in the form of a prefab. a sound is played upon explosion instantiation. then destroys that prefab after 5 seconds. otherwise nothing happens to the grenade object on collision.
I apologize for the confusing names, these are two objects (asteroids and a rocket) and I need to add a rocket explosion to this script (to designate a rocket). At the same time, only the asteroid will explode.
Your answer
Follow this Question
Related Questions
Move object to some random position once it gets in collision 1 Answer
How to use tag for all players in the Instantiate. 0 Answers
Saving Object Name in a database when it is clicked ? 0 Answers
2d obj look at limit in unity 0 Answers
Unity2D raycast to check for a wall, Issues. ~Still not solved...Anybody?~ 2 Answers