1
public class PlayerCollision : MonoBehaviour {

    public bool doorIsOpen = false;
    float doorTimer = 0.0f;
    public float doorOpenTime  = 3.0f;
    public AudioClip doorOpenSound; 
    public AudioClip doorShutSound;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    void OnControllerColliderHit(ControllerColliderHit hit){
        if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false){ 
            //doorIsOpen = true;
            OpenDoor(hit.gameObject);
        }           
    }

    void OpenDoor(GameObject door){      
        door.audio.PlayOneShot(doorOpenSound,1);
    }

}

在此处输入图像描述

以上,我用开门和关门声音片段启动了我的 2 个公共变量

当我调试代码时,变量变为空

在此处输入图像描述

4

0 回答 0