嘿傢伙我有我的代碼問題,我無法弄清楚,我試圖讓它如此,當玩家與門碰撞或觸摸它它播放動畫。問題是動畫根本無法播放。不知道爲什麼門不會打開
還請記住,門腳本連接到門上。
using UnityEngine;
using System.Collections;
public class DoorOpen : MonoBehaviour
{
//this variable will decide wether door is open or not, its initially on false because the door is closed.
bool isDoorOpen = false;
//this variable will play the audio when the door opens
public AudioSource sound01;
void Start()
{
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Bathroom_Door" && Input.GetKeyDown(KeyCode.F))
{
GetComponent<Animation>().Play("DoorO");
sound01.Play();
//this variable becomes true because the door is open
isDoorOpen = true;
}
}
// Update is called once per frame
void Update()
{
}
}
舒爾它是'DoorO'?你是不是指'Door0'? – joe
是的,我檢查了它。我的代碼有問題嗎? – DialUp
它現在設置的方式必須在同一幀中按下F鍵,OnCollisionEnter事件纔會生成,因此門並不總是打開。 – ColmanJ