我一直试图为自己的统一水平做一个滑动门,并且设法设置了动画,但是原本应该将功能与对象链接起来的脚本却无法正常工作。
这是钥匙卡的脚本:
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);
}
}
}
有任何想法吗?
最佳答案
您的代码中的OnTriggerEnter
方法没有正确的大写字母。您有两种不同的拼写,但它们都错了。它必须完全是OnTriggerEnter
(对于具有OnTriggerEnter2D
而不是Collider2D
的对象,则必须为Collider
)。