我一直试图为我的统一级别制作一个推拉门,我已经设法设置了动画,但是应该将功能与对象联系起来的脚本无效。
以下是钥匙卡的脚本:
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);
}
}
}
任何想法?
答案 0 :(得分:3)
您的代码中的OnTriggerEnter
方法没有正确的大小写。你有两种不同的拼写,它们都是错的。对于OnTriggerEnter
而不是OnTriggerEnter2D
的对象,它必须完全 Collider2D
(或Collider
。