【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); //激活玩家受伤事件                    
                                                                                        //延迟播放动画s
                GameFacade.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);
        //暂停两秒后再显示文字   
        //DOtween
        transform.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)


---


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/579184.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【C++】简易二叉搜索树

目录 一、概念&#xff1a; 二、代码实现&#xff1a; 大致结构&#xff1a; 1、遍历&#xff1a; 2、insert 3、find 4、erase 三、总结&#xff1a; 一、概念&#xff1a; 二叉搜索树又称为二叉排序树&#xff0c;是一种具有特殊性质的二叉树&#xff0c;对于每一个节…

springboot+springsecurity+vue前后端分离权限管理系统

有任何问题联系本人QQ: 1205326040 1.介绍 优秀的权限管理系统&#xff0c;核心功能已经实现&#xff0c;采用springbootvue前后端分离开发&#xff0c;springsecurity实现权限控制&#xff0c;实现按钮级的权限管理&#xff0c;非常适合作为基础框架进行项目开发。 2.效果图…

ICP点云配准初探

ICP点云配准初探 1 简介2 常用的点云配准算法3 ICP&#xff08;Iterative Closest Point&#xff0c;最近点迭代法&#xff09;3.1 ICP要解决的问题3.2 ICP的核心思想3.3 算法流程3.4 总结 4 ICP优缺点 1 简介 在逆向工程&#xff0c;计算机视觉&#xff0c;文物数字化等领域中…

香港BTC、ETH现货ETF同时通过,对行业意义几何?

香港比美国更快一步通过以太坊现货 ETF。 2024 年 4 月 15 日&#xff0c;香港嘉实国际资产管理有限公司&#xff08;Harvest Global Investments&#xff09;今天宣布&#xff0c;得到香港证监会的原则上批准&#xff0c;将推出两大数字资产&#xff08;比特币及以太坊&#…

​可视化大屏C位图:园区鸟瞰

将园区鸟瞰图作为可视化大屏设计的焦点图有以下几个好处&#xff1a; 提供全局视图&#xff1a;园区鸟瞰图可以展示整个园区的布局和结构&#xff0c;提供全局视图。这对于大型园区或复杂的场所来说尤为重要&#xff0c;用户可以一目了然地了解整个园区的规模、分布和关联关系…

go设计模式之工厂方法模式

工厂方法模式 什么是工厂方法模式 工厂方法模式是一种创建型设计模式&#xff0c;它定义了一个用于创建对象的接口&#xff0c;让子类决定实例化哪一个类。工厂方法使一个类的实例化推迟到其子类。 这个接口就是工厂接口&#xff0c;子类就是具体工厂类&#xff0c;而需要创…

频率分析和离散傅里叶变换——DSP学习笔记四

背景知识 四种基本的傅里叶变换 基本思想&#xff1a;将信号表示为不同频率 正弦分量的线性组合 正弦信号和复指数时间信号的有用特性 相同频率但不同相位的正弦信号的任何线性组合&#xff0c;都是有着相同频率但不同相位&#xff0c;且幅度可能受改变的正弦信号。 复指数时…

EXCEL表格中的数字,为什么每次打开会自动变成日期?

一、典型现象 在工作中&#xff0c;有时会发现公司里的报表&#xff0c;经过多人多次的重复的使用和修改后&#xff0c;会出现这种情况&#xff1a; 1.在表格里按照需要输入数字&#xff0c;保存工作簿。 2.然而&#xff0c;再次打开工作簿&#xff0c;里面的数字变成日期&a…

Linux多线程(二) 线程同步 信号量互斥锁读写锁条件变量

多个进程同时访问某些资源时&#xff0c;必须考虑同步问题&#xff0c;以确保任一时刻只有一个进程可以拥有对资源的独占式访问。通常&#xff0c;程序对关键资源的访问代码只是很短的一段&#xff0c;我们称这段代码为关键代码段或者临界区&#xff0c;对进程同步&#xff0c;…

火绒安全概述

页面简介&#xff1a; 火绒安全是一款集多种安全功能于一体的国产软件&#xff0c;旨在为用户提供全面的计算机保护。本页面将详细介绍火绒安全的核心功能和使用方式。 页面内容概览&#xff1a; 杀毒防护 实时监控&#xff1a;详细介绍火绒安全如何实时检测系统中的文件和程序…

【强训笔记】day5

NO.1 思路&#xff1a;找到数量最小的字符&#xff0c;就可以知道you的数量&#xff0c;用o的数量减去you的数量再减去1就是oo的数量。 代码实现&#xff1a; #include<iostream>using namespace std;int main() {int q;cin >> q;int a, b, c;while (q--){cin &g…

Java web应用性能分析之【sysbench基准测试】

Java web应用性能分析之【CPU飙高分析之MySQL】-CSDN博客 Java web应用性能分析之【Linux服务器性能监控分析概叙】-CSDN博客 Java web应用性能分析概叙-CSDN博客 Java web应用性能分析之【基准测试】-CSDN博客 上面基本科普了一下基准测试&#xff0c;这里我们将从sysbench…

雷电模拟器,安卓手机模拟器电脑端去广告精简优化版 v9.0.70 (240427)

软件介绍 在众多安卓模拟器中&#xff0c;雷电模拟器作为电脑端手游的首选平台&#xff0c;由上海畅指网络科技有限公司研发并免费提供给用户。此模拟器搭载了先进的内核技术&#xff08;基于版本&#xff09;&#xff0c;确保了软件运行的高速性和稳定性。雷电模拟器还引入了…

【yolov8yolov5驾驶员抽烟-打电话-喝水-吃东西检测】

YOLO算法DMS驾驶员抽烟-打电话-喝水-吃东西检测数据集 YOLOv8和YOLOv5是深度学习中用于目标检测的先进算法&#xff0c;它们在实时性和准确性方面表现出色&#xff0c;适用于各种视频监控和图像处理应用&#xff0c;包括驾驶员行为监测。这些算法通过单次前向传播即可预测图像…

javaScript基础2

javaScript 一.运算符二.流程控制1.顺序流程控制2.分支流程控制&#xff08;1&#xff09;if/if..else/if多分支&#xff08;2&#xff09;.三元表达式&#xff08;4&#xff09;.switch和if else区别 3.循环流程控制(1).for循环/双重for循环(2).一些例子(3).while循环/do..whi…

SpringBoot 接口防抖(防重复提交)的一些实现方案

啥是防抖 所谓防抖&#xff0c;一是防用户手抖&#xff0c;二是防网络抖动。 在Web系统中&#xff0c;表单提交是一个非常常见的功能&#xff0c;如果不加控制&#xff0c;容易因为用户的误操作或网络延迟导致同一请求被发送多次&#xff0c;进而生成重复的数据记录。 要针对…

【C++ | 复合类型】结构体、共用体、枚举、引用

&#x1f601;博客主页&#x1f601;&#xff1a;&#x1f680;https://blog.csdn.net/wkd_007&#x1f680; &#x1f911;博客内容&#x1f911;&#xff1a;&#x1f36d;嵌入式开发、Linux、C语言、C、数据结构、音视频&#x1f36d; ⏰发布时间⏰&#xff1a; 本文未经允许…

深入理解冯诺依曼体系结构

文章目录 冯诺依曼体系结构概念冯诺依曼体系结构的优势冯诺依曼体系结构的现实体现 冯诺依曼体系结构概念 冯诺依曼体系结构也称普林斯顿结构&#xff0c;是现代计算机发展的基础。它的主要特点是“程序存储&#xff0c;共享数据&#xff0c;顺序执行”&#xff0c;即程序指令和…

芋道微服务功能介绍(限免)

&#x1f339;作者主页&#xff1a;青花锁 &#x1f339;简介&#xff1a;Java领域优质创作者&#x1f3c6;、Java微服务架构公号作者&#x1f604; &#x1f339;简历模板、学习资料、面试题库、技术互助 &#x1f339;文末获取联系方式 &#x1f4dd; 系列文章目录 第一章 芋…

Datart 扩装下载功能之PDF和图片下载

Datart 扩装下载功能之PDF和图片下载 首先下载依赖 yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts -y 然后下载安装chrome yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm 查看chrome版本号 google…
最新文章