I have been working with roll a ball to learn coding. I am trying to add sounds to the boxes when my ball collides with them. What can I be doing wrong? Am using the last unity version.
A few tips on helping others to help you.
Use Code tags when posting code:
Also you state what you want to happen, and ask for help… but you don’t state what your code is actually doing (whats going wrong). Is it not playing the Audio at all. Is playing too late, distorted, etc?
On thing you can check if your triggers are happening at all:
void OnTriggerEnter()
{
Debug.Log("The trigger is being Called!");
AudioSource audio = GetComponent<AudioSource>();
audio.Play ();
}
You can also check that your AudioSource and AudioClip are set correctly by playing the sound when you press play with this:
Again thanks so much. Well it looks like the trigger is being called every time i hit the cube but no sound. But when i put it in the start menu it works. And it plays sound. Also this is C# I am trying to have a ball pickup collectables.
Can not figure this out for my player ball I have a script name collision. And for my the item I want to pick a ball. It seems they cancel each other out. when I turn off the collision script I hear the sound when my ball touches the item I want to pick up but does not pickup the item. When I turn the collision script on it picks up the item but makes no sound. How can I solve this. I do see a debug I wrote that does pop up in the console so I am triggering it.
using UnityEngine;
using System.Collections;
public class collider : MonoBehaviour {
void FixedUpdate()
{
}
void OnTriggerEnter(Collider other)
{
Debug.Log ("Yahoo");
if (other.gameObject.CompareTag ("Pick"))
{
other.gameObject.SetActive (false);
}
}
void OnTriggerEnter()
{
Debug.Log ("Music Works");
AudioSource play = GetComponent<AudioSource> ();
play.Play ();
}
}
And here is the music code
using UnityEngine;
using System.Collections;
public class musicfx : MonoBehaviour {
void OnTriggerEnter()
{
Debug.Log ("Music Works");
AudioSource play = GetComponent<AudioSource> ();
play.Play ();
}
}
Thanks I can not figure why they cancel each other out.