【问题标题】:Colliders and sound碰撞器和声音
【发布时间】:2022-01-19 16:37:01
【问题描述】:

当我进入某个游戏对象的对撞机时,我想根据它是第一次进入球体对撞机还是第二次或第三次播放不同的声音。这一切都可以写在同一个脚本中吗?

【问题讨论】:

    标签: unity3d arkit


    【解决方案1】:
    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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多