hi. I have a game and 2 objects in game.I want to play sound when two objects touch each other.
here is my code:
public AudioSource ses;
public Collider2D küp;
Collider2D obje;
void Start () {
obje = gameObject.GetComponent<Collider2D>();
ses = gameObject.GetComponent<AudioSource>();
}
void Update () {
if (obje.IsTouching(küp))
{
ses.Play();
}
}
But with this code i cant get what i want.This code plays sound while objects touching each other.But ı want to play just one time when they first time touch each other