- Home /
Trigger sound doesn't work
Here is my code , i was trying to do it in many ways , I saw a lot of tutorials but nothing work and I dont know why ... Thanks to reply
using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour {
public AudioClip sound;
public AudioSource source;
public float Volume;
public float speed;
public Text countText;
public Text winText;
public Vector3 userAcceleration;
private Rigidbody rb;
private int count;
void Start ()
{
source = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
Screen.sleepTimeout = SleepTimeout.NeverSleep;
}
void FixedUpdate ()
{
if(SystemInfo.deviceType == DeviceType.Desktop)
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
else
{
/*float moveH = Input.gyro.userAcceleration.x;
float moveV = Input.gyro.userAcceleration.y;
Vector3 movement = new Vector3 (moveH, 0.0f, moveV);
rb.AddForce(movement * speed * Time.deltaTime);*/
float moveHorizontal = Input.acceleration.x;
float moveVertical = Input.acceleration.y;
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Point"))
{
source.PlayOneShot(sound, Volume);
count = count + 1;
SetCountText();
other.gameObject.SetActive (false);
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12)
{
//winText.text = "Win";
SceneManager.LoadScene ("DemoScene");
}
}
}
Comment
Your answer
Follow this Question
Related Questions
On trigger , sound play 2 Answers
I want my trigger to play sound only once! 2 Answers
Alternate between two Audio clips on collision 3 Answers
Play sound on trigger, sound is coming from the trigger 1 Answer
Activate sound without Pro filters 0 Answers