【UnityRPG游戏制作】RPG项目的背包系统商城系统和BOSS大界面

2024-04-28 01:20

本文主要是介绍【UnityRPG游戏制作】RPG项目的背包系统商城系统和BOSS大界面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在这里插入图片描述


👨‍💻个人主页:@元宇宙-秩沅

👨‍💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!

👨‍💻 本文由 秩沅 原创

👨‍💻 收录于专栏:Unity基础实战

🅰️



文章目录

    • 🅰️
    • 前言
    • (==1==)商城系统
    • (==2==)背包系统
    • (==3==)BOSS系统


前言


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){ }}
}

3BOSS系统


请添加图片描述

请添加图片描述

  • 场景加载
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);}}
}
  • boss攻击
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;//-------------------------------
//-------功能: boss控制器
//-------创建者:         -------
//------------------------------public class BossController : MonoBehaviour
{public GameObject player;   //对标玩家public Animator animator;   //对标动画机public float hp = 300f;     //血量public Image hpSlider;      //血条private int attack = 30;    //敌人的攻击力public float CD_skill;      //技能冷却时间private void Start(){    animator = GetComponent<Animator>();hpSlider = transform.GetChild(0).GetChild(0).GetComponent<Image>();}private void Update(){CD_skill += Time.deltaTime; //CD一直在累加}//碰撞检测private void OnCollisionStay(Collision collision){if (collision.gameObject.tag == "Player") //检测到如果是玩家的标签{Debug.Log("接触到玩家");if (CD_skill > 3.5f)  //攻击动画的冷却时间{//触发攻击事件animator.SetBool("attack", true); //攻击动画激活 EventCenter.GetInstance().EventTrigger(PureNotification.PLAYER_INJURY); //激活玩家受伤事件                    //延迟播放动画sGameFacade.Instance.SendNotification(PureNotification.HURT_UP, attack);  //发送玩家受伤扣血的通知StartCoroutine("delay", collision.gameObject.transform );CD_skill = 0; //冷却时间归0    }}}IEnumerator delay(Transform  transform)  //协程迭代器的定义{//暂停几秒(协程挂起)yield return new WaitForSeconds(0.5f);//暂停两秒后再显示文字   //DOtweentransform.DOMoveZ(transform.localPosition.z - 3, 1); //被撞击Z轴后移}//退出 碰撞检测private void OnCollisionExit(Collision collision){//if (collision.gameObject.tag == "Player") //检测到如果是玩家的标签{Debug.Log("玩家退出");animator.SetBool("attack", false);PlayerContorller.GetInstance().animator.SetBool("hurt", false);}}//范围触发检测private void OnTriggerStay(Collider other){if (other.tag == "Player")  //检测到如果是玩家的标签{//让怪物看向玩家transform.LookAt(other.gameObject.transform.position);animator.SetBool("walk", true);//并且向其移动transform.Translate(Vector3.forward * 1 * Time.deltaTime);}}}
⭐<font color=red >🅰️</font>⭐
----⭐[【Unityc#专题篇】之c#进阶篇】](http://t.csdn.cn/wCAYg)⭐[【Unityc#专题篇】之c#核心篇】](http://t.csdn.cn/wCAYg)⭐[【Unityc#专题篇】之c#基础篇】](http://t.csdn.cn/4NW3P)⭐[【Unity-c#专题篇】之c#入门篇】](http://t.csdn.cn/5sJaB)**⭐**[【Unityc#专题篇】—进阶章题单实践练习](http://t.csdn.cn/ue4Oh)⭐[【Unityc#专题篇】—基础章题单实践练习](http://t.csdn.cn/czWon)**⭐**[【Unityc#专题篇】—核心章题单实践练习](http://t.csdn.cn/wCAYg)---<font color= red face="仿宋" size=3>**你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!**、---
![在这里插入图片描述](https://img-blog.csdnimg.cn/430fd5b6362d48c281827ddc6a56789d.gif)---

这篇关于【UnityRPG游戏制作】RPG项目的背包系统商城系统和BOSS大界面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/942000

相关文章

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

python实现简易SSL的项目实践

《python实现简易SSL的项目实践》本文主要介绍了python实现简易SSL的项目实践,包括CA.py、server.py和client.py三个模块,文中通过示例代码介绍的非常详细,对大家的学习... 目录运行环境运行前准备程序实现与流程说明运行截图代码CA.pyclient.pyserver.py参

IDEA运行spring项目时,控制台未出现的解决方案

《IDEA运行spring项目时,控制台未出现的解决方案》文章总结了在使用IDEA运行代码时,控制台未出现的问题和解决方案,问题可能是由于点击图标或重启IDEA后控制台仍未显示,解决方案提供了解决方法... 目录问题分析解决方案总结问题js使用IDEA,点击运行按钮,运行结束,但控制台未出现http://

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

C语言小项目实战之通讯录功能

《C语言小项目实战之通讯录功能》:本文主要介绍如何设计和实现一个简单的通讯录管理系统,包括联系人信息的存储、增加、删除、查找、修改和排序等功能,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录功能介绍:添加联系人模块显示联系人模块删除联系人模块查找联系人模块修改联系人模块排序联系人模块源代码如下

SpringBoot项目中Maven剔除无用Jar引用的最佳实践

《SpringBoot项目中Maven剔除无用Jar引用的最佳实践》在SpringBoot项目开发中,Maven是最常用的构建工具之一,通过Maven,我们可以轻松地管理项目所需的依赖,而,... 目录1、引言2、Maven 依赖管理的基础概念2.1 什么是 Maven 依赖2.2 Maven 的依赖传递机

C#实现系统信息监控与获取功能

《C#实现系统信息监控与获取功能》在C#开发的众多应用场景中,获取系统信息以及监控用户操作有着广泛的用途,比如在系统性能优化工具中,需要实时读取CPU、GPU资源信息,本文将详细介绍如何使用C#来实现... 目录前言一、C# 监控键盘1. 原理与实现思路2. 代码实现二、读取 CPU、GPU 资源信息1.

Vue项目中Element UI组件未注册的问题原因及解决方法

《Vue项目中ElementUI组件未注册的问题原因及解决方法》在Vue项目中使用ElementUI组件库时,开发者可能会遇到一些常见问题,例如组件未正确注册导致的警告或错误,本文将详细探讨这些问题... 目录引言一、问题背景1.1 错误信息分析1.2 问题原因二、解决方法2.1 全局引入 Element

在C#中获取端口号与系统信息的高效实践

《在C#中获取端口号与系统信息的高效实践》在现代软件开发中,尤其是系统管理、运维、监控和性能优化等场景中,了解计算机硬件和网络的状态至关重要,C#作为一种广泛应用的编程语言,提供了丰富的API来帮助开... 目录引言1. 获取端口号信息1.1 获取活动的 TCP 和 UDP 连接说明:应用场景:2. 获取硬

JAVA系统中Spring Boot应用程序的配置文件application.yml使用详解

《JAVA系统中SpringBoot应用程序的配置文件application.yml使用详解》:本文主要介绍JAVA系统中SpringBoot应用程序的配置文件application.yml的... 目录文件路径文件内容解释1. Server 配置2. Spring 配置3. Logging 配置4. Ma