1
所以我有一個腳本,當我與標記的遊戲對象發生碰撞時可以計算點數。當我擊中不同的物體時,我想讓遊戲發出不同的聲音。所以這是我的腳本:如何在單個遊戲對象上添加多個音頻源?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class POINTS1 : MonoBehaviour
{
public Text countText;
public Text winText;
private int count;
void Start()
{
count = 0;
SetCountText();
winText.text = "";
PlayerPrefs.SetInt("score", count);
PlayerPrefs.Save();
count = PlayerPrefs.GetInt("score", 0);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive(false);
count = count + 100;
SetCountText();
}
else if (other.gameObject.CompareTag("minus300"))
{
other.gameObject.SetActive(false);
count = count - 300;
SetCountText();
{
GetComponent<AudioSource>().Play();
}
}
PlayerPrefs.SetInt("score", count);
PlayerPrefs.Save();
count = PlayerPrefs.GetInt("score", 0);
}
void SetCountText()
{
PlayerPrefs.SetInt("score", count);
PlayerPrefs.Save();
count = PlayerPrefs.GetInt("score", 0);
countText.text = "Score: " + count.ToString();
if (count >= 5000)
{
winText.text = "Good Job!";
}
}
}
那麼我如何有不同的拾音對象和Minus300對象的聲音?謝謝!
如果你在這裏沒有得到答案,你可能還想嘗試http://gamedev.stackexchange.com/ – tarun713