[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图

      

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM