[Unity3D] 按下按键打开背包

 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图

      

时间若流水,恍惚间逝去
原文地址:https://www.cnblogs.com/alanshreck/p/13663892.html