第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Unity 為什么這個(gè)觸發(fā)器不能正常工作

Unity 為什么這個(gè)觸發(fā)器不能正常工作

C#
牛魔王的故事 2021-06-03 14:58:50
我一直在嘗試在 Unity C# 中制作一扇門,并且我在大部分情況下都可以使用它,但似乎不起作用的是讓玩家在站立時(shí)仍在觸發(fā)器內(nèi)時(shí)讓玩家通過。當(dāng)我在扳機(jī)中移動時(shí),門會起作用,但當(dāng)我靜止不動時(shí),它也不會,只要按下開門按鈕,就會立即傳送玩家,我知道如何修復(fù)。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 hallwaypublic GameObject Entrancedoor;public bool isbossdoor;public bool playerisentering;//Door in the bossroompublic 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);                        }                    }                //}            }   
查看完整描述

1 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

Woops 忘了提到我前段時(shí)間解決了這個(gè)問題,我想我會把我用來幫助任何有類似問題的人的腳本放進(jìn)去。


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);

                        }

                    }

                //}

            }

            if (NeedsKey == false)

            {

                if ( playerisentering == true

                    //Input.GetButton("EnterDoor") || Input.GetKey(KeyCode.Q)

                    )

                {

                    Debug.Log("ButtonPressed");

                    if (isbossdoor == false)

                    {

                        collision.transform.position = ExitBossdoor.transform.position;

                        SpawnBossRoom.SetActive(true);

                    }

                    if (isbossdoor == true)

                    {

                        collision.transform.position = Entrancedoor.transform.position;

                        SpawnBossRoom.SetActive(false);

                    }

                }

            }

        }

    }

}

private void OnTriggerExit2D(Collider2D collision)

{

    if(collision.gameObject.tag == "Player")

    {

        Playerisatdoor = false;

    }

}

private void Update()

{

    if(Playerisatdoor == true)

    {

        if(Input.GetButton("EnterDoor") || Input.GetKey(KeyCode.Q))

        {

            StartCoroutine("TeleportPlayer");

        }

        else

        {

            playerisentering = false;

        }

    }

}

public IEnumerator TeleportPlayer ()

{

    yield return new WaitForSeconds(TpDelay);

    playerisentering = true;

    yield return new WaitForSeconds(1);

}

}





// RoomKey Numbers:

/* 




*/



查看完整回答
反對 回復(fù) 2021-06-05
  • 1 回答
  • 0 關(guān)注
  • 420 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號