Triggers won't recognize tags other than the actual player
Hello, I am fairly new to Unity and have come across a problem that I can't seem to find an answer to. I created a 3D GameObject cube and set up a box collider as a trigger. After that I wrote a script to make it play an audio track when the object attached to my player interacts with the trigger. My goal is to have the character look up and trigger an audio file. However, I tagged my object "PlayerObject" but the trigger doesn't seem to recognize it. It would be great to figure out what the problem is. Thanks!
Additional info: The object is a child of the player so it moves with it
The script works if the trigger interacts with the character only
There are no script errors and everything is set up in the inspector
I have an audio source and script attached to the trigger
Here is the script for the trigger: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class lookupNow : MonoBehaviour {
public GameObject largecube;
public AudioClip SoundToPlay;
public float volume;
AudioSource audio;
public bool alreadyPlayed = false;
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "PlayerObject")
{
audio = GetComponent<AudioSource> ();
}
if (!alreadyPlayed)
{
audio.PlayOneShot (SoundToPlay, volume);
alreadyPlayed = true;
}
} }
Your answer
Follow this Question
Related Questions
How to mute multi-able audioclips within a single audiosource? 0 Answers
Issues with randomised objectpool, tag setting and re-setting, general noob issues 0 Answers
Cannot Figure out How to use panStereo 0 Answers
AUDIO DATA to STATIC WAVEFORM DISPLAY? 1 Answer
Basic setup for spatial audio 0 Answers