对撞机和声音
Colliders and sound
当我为某个游戏对象进入碰撞器时,我想根据它是第一次进入球体碰撞器还是第二次或第三次播放不同的声音。这些都可以写在同一个脚本中吗?
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
//attach in inspector or make private and get with code in the Start()
public AudioSource audioSource1;
public AudioSource audioSource2;
void Start() {
// get audioSources optional
}
int colCounter = 0;
void OnCollisionEnter(Collision collision) {
colCounter++;
if (colCounter == 1)
audioSource1.Play();
else
audioSource2.Play();
}
}
当我为某个游戏对象进入碰撞器时,我想根据它是第一次进入球体碰撞器还是第二次或第三次播放不同的声音。这些都可以写在同一个脚本中吗?
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
//attach in inspector or make private and get with code in the Start()
public AudioSource audioSource1;
public AudioSource audioSource2;
void Start() {
// get audioSources optional
}
int colCounter = 0;
void OnCollisionEnter(Collision collision) {
colCounter++;
if (colCounter == 1)
audioSource1.Play();
else
audioSource2.Play();
}
}