Hi, how do I tag the second object in the code below?
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
}
}
}