Hello I'm Sky,
In my project, I want to have sound when my moving game object only if collide(pass through it) with two game object with rigidbody and a collider. Please help me fast, I need to finish by tomorrow morning. qJake@username I think you could help me :) Thank you Sir.
Answer by JatMidGrade · Nov 22, 2016 at 03:56 PM
Not entirely sure if I understand your question correctly, but here's an attempt at an option for you. Does it have to collide with BOTH objects to play the sound, or just one at any given point in time?
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void OnTriggerEnter(Collider other) {
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
}
}
If it requires you collide with both, you'll have to have some boolean values and if statements to confirm both colliders have been triggered.
Thank you Jat$$anonymous$$idGrade. $$anonymous$$y logic there was a mistake. $$anonymous$$y game is to avoid the in co$$anonymous$$g object by the player. When success to avoid the in co$$anonymous$$g object then we will need to have sound. Then if my in co$$anonymous$$g object was collide my player and I don't want to trigger the sound. I only think about is either collide with my player or not, I would have sound. So could you think about a way to implement this situation.
Your answer
Follow this Question
Related Questions
Trouble with collison and trigger's 1 Answer
OnTriggerEnter vs distance check in Update 1 Answer
Prevent changing speed at collision 0 Answers