【发布时间】:2022-06-29 04:10:55
【问题描述】:
我正在做一个学校项目,我需要有关 trigger2dstay 的帮助。我试图让它成为当我的玩家的对撞机标签进入触发器对撞机时,弹出一个有效的图像,但我也试图让它在播放做同样的事情并按下 E kbd>,它会触发一个动画,但是当我的 2d 播放器走进触发器并按下 E 时,什么也没有发生。按下 E 仅在您移动并按下它时起作用,而不是静止不动。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class buttonele : MonoBehaviour
{
public GameObject Obje;
public GameObject blockers;
public GameObject eledoorn;
public GameObject eledormation;
bool Unlock;
// Start is called before the first frame update
void Start()
{
Obje.SetActive(false);
eledormation.SetActive(true);
Unlock = false;
}
void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Player")
{
Unlock = true;
Obje.SetActive(true);
}
if (Unlock == true && Input.GetKeyDown(KeyCode.E))
{
Destroy(blockers);
Destroy(eledoorn);
eledormation.GetComponent<Animator>().Play("eleopen");
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
Obje.SetActive(false);
}
}
}
【问题讨论】:
-
请任何人!任何事情都有助于这是最后一分钟!!!!
-
您只需将 GetKeyDown Check 和所有相关代码移至您的 Update 方法即可解决问题。
-
这个问题不是关于unityscript,而是关于c#
标签: c# visual-studio unity3d