大家好,欢迎来到IT知识分享网。
👨💻个人主页:@元宇宙-秩沅
👨💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!
👨💻 本文由 秩沅 原创
👨💻 收录于专栏:就业宝典
👨💻 专栏交流 | 🧧 |
---|---|
🟥✨Unity100个实战基础✨🟥 | 🎁 |
🟦✨ Unity100个精华一记✨🟦 | 🎁 |
🟩✨ Unity50个demo案例教程✨🟩 | 🎁 |
🟨✨ Unity100个精华细节BUG✨🟨 | 🎁 |
文章目录
⭐前言⭐
–
🎶(五) 道具相关
(1)蘑菇炸彈
using System.Collections; using System.Collections.Generic; using UnityEngine; //------------------------------- //-------功能: 炸彈檢測 //-------创建者: ------- //------------------------------ public class Boom : MonoBehaviour {
public ParticleSystem particle1, particle2; // Start is called before the first frame update void Start() {
particle1 = transform.GetChild(0).GetChild(0).GetComponent<ParticleSystem>(); //獲取例子系統組件 particle2 = transform.GetChild(1).GetChild(0).GetComponent<ParticleSystem>(); //獲取例子系統組件 } private void OnCollisionEnter(Collision collision) {
if(collision.gameObject.tag == "Player") {
particle1.Play(); //播放動畫 particle2.Play(); Destroy(gameObject,0.8f); //延時銷毀 } } }
(2)武器道具
(3)BOSS房间道具
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; //------------------------------- //-------功能: Boss房间钥匙逻辑 //-------创建者: ------- //------------------------------ public class Key : MonoBehaviour {
private void OnTriggerStay(Collider other) {
if (other.gameObject .tag == "Player"&& Input.GetKeyDown(KeyCode.F)) {
SceneManager.LoadScene(1); } } }
(4)背包道具
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.UI; //------------------------------- //-------功能: 背包道具功能逻辑 //-------创建者: ------- //------------------------------ public class PropItem : MonoBehaviour {
public Sprite PresentSprite; //当前item的精灵 public Button button; private Transform weapon; //生成武器的位置 void Start() {
//获取当前的道具物品的精灵图集 PresentSprite = transform.GetChild(0). GetComponent<Sprite>(); weapon = PlayerContorller.GetInstance().weaponPosition; switch (PresentSprite.name) {
case "BossTicket": //boss钥匙 button.onClick.AddListener(()=> {
SceneManager.LoadScene(1); }); break; case "Bp1": button.onClick.AddListener(() => {
GameFacade.Instance.SendNotification(PureNotification.HURT_UP, -30); //发送小还丹指令 }); break; case "Bp5": button.onClick.AddListener(() => {
GameFacade.Instance.SendNotification(PureNotification.HURT_UP, -50);//发送中怀丹指令 }); break; case "Item_30": button.onClick.AddListener(() => {
GameFacade.Instance.SendNotification(PureNotification.HURT_UP, -100);//发送大怀丹指令 }); break; //发送武器装备逻辑 case "weapon1": button.onClick.AddListener(() => {
Instantiate(Resources.Load<GameObject>("Perfab/weapon/Weapon1"), weapon.position , Quaternion.identity); }); break; case "weapon2": button.onClick.AddListener(() => {
Instantiate(Resources.Load<GameObject>("Perfab/weapon/Weapon2"), weapon.position, Quaternion.identity); }); break; case "weapon3": button.onClick.AddListener(() => {
Instantiate(Resources.Load<GameObject>("Perfab/weapon/Weapon3"), weapon.position, Quaternion.identity); }); break; case "weapon4": button.onClick.AddListener(() => {
Instantiate(Resources.Load<GameObject>("Perfab/weapon/Weapon4"), weapon.position, Quaternion.identity); }); break; default: break; } } // Update is called once per frame void Update() {
} }
(5)钥匙道具
🎶(六) 系统相关
(1)商城系统
- 商品逻辑
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using static UnityEditor.Progress; //------------------------------ //-------功能: 商城物品按钮 //-------创建者: //------------------------------ public class ShopItem : MonoBehaviour {
public Button item; //商品按钮 public Text price; public int priceVaule; //商品价格 public GridLayoutGroup backPack; //购买栏 public int allDamon; private Vector3 off = new Vector3(1.8f,1,1); //设定物品框的大小 Button btu; private void Start() {
item = GetComponent<Button>(); //将价格进行转换 priceVaule = Convert.ToInt32(price.text); item.onClick.AddListener(()=> //按钮点击事件的添加 {
Debug.Log("现在的水晶为:"+PlayerContorller.GetInstance().damonNum); Debug.Log("当前的价格为:"+ priceVaule); //如果钱够了 if ( priceVaule <= PlayerContorller.GetInstance().damonNum) {
btu = Instantiate(item); //实例化按钮 //减少钻石的数量 Destroy(btu.GetComponent<ShopItem>()); //移除该商品的脚本 PlayerContorller.GetInstance().ReduceDamon(priceVaule, Instantiate(btu)); btu.transform.SetParent(backPack.transform); //移动到购买栏下方 btu.transform.localScale = off;//初始化大小 } else {
GameFacade.Instance.SendNotification(PureNotification.SHOW_PANEL,"TipPanel"); } }); } private void Update() {
if (backPack != null) {
} } }
- 面板逻辑
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //------------------------------- //-------功能: 商城系统 //-------创建者: ------- //------------------------------ public class StoreView : BasePanel {
public GridLayoutGroup StoreGrid; public GridLayoutGroup BackGrid; public Button backBtu; public Button bugPack;//放入背包 }
- 面板视图中介(PureMVC)
using PureMVC.Interfaces; using PureMVC.Patterns.Mediator; using System.Collections; using System.Collections.Generic; using UnityEngine; //------------------------------- //-------功能: ------- //-------创建者: ------- //------------------------------ public class StoreViewMediator : Mediator {
//铭牌名 public static string NAME = "StoreViewMediator"; /// <summary> /// 构造函数 /// </summary> public StoreViewMediator() : base(NAME) {
} /// <summary> /// 重写监听感兴趣的通知的方法 /// </summary> /// <returns>返回你需要监听的通知的名字数组</returns> public override string[] ListNotificationInterests() {
return new string[] {
}; } /// <summary> /// 面板中组件设置(监听相关) /// </summary> /// <param name="stateView"></param> public void setView(StoreView storeView) {
ViewComponent = storeView; if(ViewComponent == null) {
Debug.Log("面板是空的"); } storeView.backBtu .onClick.AddListener(()=> {
SendNotification(PureNotification.HIDE_PANEL, "StorePanel"); }); storeView.bugPack.onClick.AddListener(() => {
}); } /// <summary> /// 玩家受伤逻辑 /// </summary> public void Hurt() {
} /// <summary> /// 重写处理通知的方法,处理通知,前提是完成通知的监听 /// </summary> /// <param name="notification">通知</param> public override void HandleNotification(INotification notification) {
switch (notification.Name) {
} } }
(2)背包系统
- 背包系统视图
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //------------------------------- //-------功能: 背包系统视图 //-------创建者: //------------------------------ public class BackpackView : BasePanel {
public Button back; //退出按钮 public GridLayoutGroup grid; /// <summary> /// 更新背包中的内容 /// </summary> /// <param name="itemBtu"></param> public void AddItem(Button itemBtu) {
//将传入的按钮设置为布局下面的子物体 itemBtu.transform.SetParent (grid.gameObject.transform ); itemBtu.transform.localScale = Vector3.one ;//初始化商品道具大小 } } + 背包系统视图中介 ```csharp using PureMVC.Interfaces; using PureMVC.Patterns.Mediator; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //------------------------------- //-------功能: 背包面板视图中介 //-------创建者: //------------------------------ /// <summary> /// 状态面板视图中介 /// 固定: /// 1.继承PureMVC的Mediator脚本 /// 2.写构造函数 /// 3.重写监听通知的方法 /// 4.重写处理通知的方法 /// 5.可选:重写注册时的方法 /// </summary> public class BackpackViewMediator : Mediator {
//铭牌名 public static string NAME = "BackpackViewMediator"; /// <summary> /// 构造函数 /// </summary> public BackpackViewMediator() : base(NAME) {
} /// <summary> /// 重写监听通知的方法,返回需要的监听(通知) /// </summary> /// <returns>返回你需要监听的通知的名字数组</returns> public override string[] ListNotificationInterests() {
return new string[] {
PureNotification.UPDATA_BACKPACK //PureNotification.UPDATA_STATE_INFO }; } public void SetView(BackpackView backpackView) {
Debug.Log(backpackView + "执行SetView"); ViewComponent = backpackView; //开始按钮逻辑监听 backpackView.back.onClick.AddListener(() => {
SendNotification(PureNotification.HIDE_PANEL, "BackpackPanel"); }); } /// <summary> /// 重写处理通知的方法,处理通知 /// </summary> /// <param name="notification">通知</param> public override void HandleNotification(INotification notification) {
switch (notification.Name) {
case PureNotification.UPDATA_BACKPACK: Debug.Log("/执行视图中的放入背包的方法"); //执行视图中的放入背包的方法 (ViewComponent as BackpackView).AddItem(notification.Body as Button); break; } } }
- 购买后的商品逻辑
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using static UnityEditor.Progress; //------------------------------ //-------功能: 商城物品按钮 //-------创建者: //------------------------------ public class ShopItem : MonoBehaviour {
public Button item; //商品按钮 public Text price; public int priceVaule; //商品价格 public GridLayoutGroup backPack; //购买栏 public int allDamon; private Vector3 off = new Vector3(1.8f,1,1); //设定物品框的大小 Button btu; private void Start() {
item = GetComponent<Button>(); //将价格进行转换 priceVaule = Convert.ToInt32(price.text); item.onClick.AddListener(()=> //按钮点击事件的添加 {
Debug.Log("现在的水晶为:"+PlayerContorller.GetInstance().damonNum); Debug.Log("当前的价格为:"+ priceVaule); //如果钱够了 if ( priceVaule <= PlayerContorller.GetInstance().damonNum) {
btu = Instantiate(item); //实例化按钮 //减少钻石的数量 Destroy(btu.GetComponent<ShopItem>()); //移除该商品的脚本 PlayerContorller.GetInstance().ReduceDamon(priceVaule, Instantiate(btu)); btu.transform.SetParent(backPack.transform); //移动到购买栏下方 btu.transform.localScale = off;//初始化大小 } else {
GameFacade.Instance.SendNotification(PureNotification.SHOW_PANEL,"TipPanel"); } }); } private void Update() {
if (backPack != null) {
} } }
⭐🅰️⭐
⭐【Unityc#专题篇】之c#进阶篇】
⭐【Unityc#专题篇】之c#核心篇】
⭐【Unityc#专题篇】之c#基础篇】
⭐【Unity-c#专题篇】之c#入门篇】
⭐【Unityc#专题篇】—进阶章题单实践练习
⭐【Unityc#专题篇】—基础章题单实践练习
⭐【Unityc#专题篇】—核心章题单实践练习
你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!、
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/140199.html