Hello!
I have tried this but it doesn’t work
using UnityEngine;
public class PlayAnimOnTrigger : MonoBehaviour {
public Animator anim;
public AudioClip sound;
void Start () {
anim.enabled = false;
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == ("Player"))
{
anim.enabled = true;
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}
}
system
January 7, 2019, 8:12pm
2
Please use code tags for posting code on the forum:
If you see someone who needs to know about code tags, please link them to this post:
Please use code tags when posting code.
You can “tag” your code by typing [984347--130826--Screenshot 2015-03-16 10.33.58.png] around your code.
There is no overt “Code” tag button that automatically tags a selection as code.
That being said, however, we can Insert code directly into the post using the “Insert Code” button:
[image]
This will bring up an “Insert” window were we can paste our code and choose…
What does exactly mean “it doesn’t work”? What is the effect?
He should play the animation and a sound on collision.
system
January 8, 2019, 4:10am
4
Have you tried to put Debug.Log inside the if to see if your code even gets there?
Do you put this script on the “enemy” (or whatever you collide with?)
Does the “mute audio” button active on the game view window?