1
我一直在試圖爲我的統一級別設置推拉門,並且我設法設置了動畫,但是應該將功能鏈接到腳本對象不起作用。製作一個可以用鑰匙解鎖的推拉門
下面是鑰匙卡的腳本:
using UnityEngine;
using System.Collections;
public class Key_Pickup_1 : MonoBehaviour {
public GameObject player;
private Player_inventory playerinventory;
void Awake()
{
playerinventory = player.GetComponent<Player_inventory>();
}
// Update is called once per frame
void onTriggerEnter()
{
if (gameObject == player)
{
playerinventory.hasKey_1 = true;
Destroy(gameObject);
}
}
}
下面是門動畫腳本:
using UnityEngine;
using System.Collections;
public class Door_Animation_1 : MonoBehaviour {
public string Open;
private Animator anim_1;
public GameObject player;
private Player_inventory playerInventory;
void Start()
{
anim_1 = GetComponent<Animator>();
player = GameObject.FindGameObjectWithTag("Player");
playerInventory = player.GetComponent<Player_inventory>();
}
void OntriggerEnter (Collider other)
{
if(other.gameObject == player)
{
if (playerInventory.hasKey_1)
{
anim_1.SetTrigger(Open);
}
}
}
什麼想法?
c#不是腳本語言 –
這不是要問「爲什麼我的代碼不工作」的地方。更新你的問題,告訴我們你跟着調試問題的辦法。謝謝。 – Cabrra
@FirstStep我不認爲他稱之爲腳本語言。附加到組件的代碼在Unity中稱爲腳本。 「Unity允許您使用腳本創建自己的組件,這些組件允許您觸發遊戲事件,隨着時間的推移修改組件屬性並以任何您喜歡的方式響應用戶輸入。」從他們的手冊。 – Timmy