为什么我的声音没有播放

时间:2012-03-01 15:58:40

标签: audio unity3d unityscript gameobject

private var doorIsOpen : boolean = false;
private var doorTimer : float = 0.0;
private var currentDoor : GameObject;

var doorOpenTime : float = 3.0;
var doorOpenSound : AudioClip;
var doorShutSound : AudioClip;

function OpenDoor (door : GameObject)
{   
    doorIsOpen = true;
    door.audio.PlayOneShot(doorOpenSound);
    door.transform.parent.animation.Play("doorOpen");
}

function OnControllerColliderHit (hit : ControllerColliderHit)
{

    if(hit.gameObject.tag == "playerDoor" && doorIsOpen == false)
    {
        OpenDoor(hit.gameObject);       
    }
}

当我的角色与门发生碰撞时,这应该发出声音但是我不明白为什么

2 个答案:

答案 0 :(得分:2)

转到Project然后Book Assets Folder然后sounds folder然后将Door_open声音拖到这些变量中:

var doorOpenSound : AudioClip;    var doorShutSound : AudioClip;

你的声音会播放。

答案 1 :(得分:1)

通过简单的步骤; 首先通过一些调试验证您的代码是否到达OnControllerColliderHit,然后到达OpenDoor(hit.gameObject); 还要确认它可以播放door.transform.parent.animation.Play(“doorOpen”); (并以正常代码而不是有条件的方式发出声音)

从代码片段中,您的“playerDoor”定义可能在其他地方不正确