我一直在尝试在 Unity C# 中制作一扇门,并且我在大部分情况下都可以使用它,但似乎不起作用的是让玩家在站立时仍在触发器内时让玩家通过。当我在扳机中移动时,门会起作用,但当我静止不动时,它也不会,只要按下开门按钮,就会立即传送玩家,我知道如何修复。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BaseDoorScript : MonoBehaviour {
public float NeededKeyNumber;
public float TpDelay;
public bool CanOpen;
public bool NeedsKey;
public bool Playerisatdoor;
//Door in the hallway
public GameObject Entrancedoor;
public bool isbossdoor;
public bool playerisentering;
//Door in the bossroom
public GameObject ExitBossdoor;
public GameObject SpawnBossRoom;
public void OnTriggerStay2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
Playerisatdoor = true;
Debug.Log("Player Is Here");
//collision.transform.position = ExitBossdoor.transform.position;
if (CanOpen == true && Playerisatdoor == true)
{
var PlayerKey = collision.GetComponent<KeyScript>().KeyNumber;
if (NeedsKey == true)
{
//if (Input.GetButton("EnterDoor"))
//{
if (PlayerKey == NeededKeyNumber)
{
if (isbossdoor == false)
{
collision.transform.position = ExitBossdoor.transform.position;
SpawnBossRoom.SetActive(true);
}
if (isbossdoor == true)
{
collision.transform.position = Entrancedoor.transform.position;
SpawnBossRoom.SetActive(false);
}
}
//}
}
临摹微笑
相关分类