1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class OpenTheBag : MonoBehaviour 6 { 7 //將要顯示的背包拖入 8 public GameObject MyBag; 9 //背包狀態 10 private bool BagState ; 11 12 13 void Update() 14 { 15 //調用判斷方法 16 OpenMyBag(); 17 18 } 19 20 private void OpenMyBag() { 21 //默認狀態賦值為false 22 BagState = MyBag.activeSelf; 23 //如果按下按鍵i 24 if (Input.GetKeyDown(KeyCode.I)) { 25 //將狀態設置為false的方面狀態true 26 BagState = !BagState; 27 //將背包的狀態設置為狀態值 28 MyBag.SetActive(BagState); 29 } 30 } 31 }
感謝麥克老師的背包講解
BiliBili :https://www.bilibili.com/video/BV1LJ411X78s
效果GIF圖