口袋妖怪_金沙(游戏开发)二

时间:2020-04-20
本文章向大家介绍口袋妖怪_金沙(游戏开发)二,主要包括口袋妖怪_金沙(游戏开发)二使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

谈论游戏的侧重点和方向

很多人说,开发游戏应该要把重点放在游戏的玩法和技巧上面,一款游戏的好坏,绝不是因为它有华丽的画面而出名的,比如去年的"3a级"大作《某歌》,这里并没有贬低谁的意思,只是说,一款真正好玩的游戏,它所表达出来的思想情感,可以传达给玩家,并能够引起大多数人的共鸣,我称之为游戏的灵魂,如果一款游戏没有这样所谓的灵魂,实则如行尸走肉一般,毫无乐趣可言。(这也是独立游戏开发者所注重的地方)

又比如《只狼》这款成功的大作,游戏中的战斗场景处理的很好,尤其的人物的战斗方式,“一闪”这个本身就是一种游戏的特色,从母公司开发游戏的历程中,传承下来的东西。这里便是很多人玩起来为什么这么“爽快”的原因。

背包系统

本章开发背包系统,首先我们要实现以下功能(能对物体进行拾起)(点击背包中的物品能够使用(让物品消失))(可以自动整理背包

ok,一步一步进行,我先将背包弄出来

定义一个脚本:back(这是一个菜单,有(物品)(精灵)(时间)(道馆)(保存)(退出))

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//这里先弄好一个大体的框架,因为我们希望该脚本可以作为我们的游戏菜单,所以我将它挂载到摄像机上面
public class back : MonoBehaviour { //获取按键消息 public GameObject rc; //public float set_high, set_width, w, h; //背包栏 public GameObject back_gree; //精灵栏 public GameObject back_spirits; //public GUIStyle spr; public Sprite sr; //打开选项 public GameObject gb; // Use this for initialization void Start () { //开始的剧情 } void Update() //打开背包 { if (rc.GetComponent<play>().pand) { //失败案例 /*GUI.color = Color.black; GUI.BeginGroup(new Rect(set_width, set_high, w, h)); GUI.Button(new Rect(set_width, set_high, w, h / 6), "物品"); GUI.Button(new Rect(set_width, set_high + h / 6, w, h / 6), "精灵"); GUI.Button(new Rect(set_width, set_high + h / 3, w, h / 6), "时间"); GUI.Button(new Rect(set_width, set_high + h / 2, w, h / 6), "道馆认证书"); GUI.Button(new Rect(set_width, set_high + (h / 6) * 4 , w, h / 6), "保存"); GUI.Button(new Rect(set_width, set_high + (h / 6) * 5, w, h / 6), "退出"); //按钮 GUI.EndGroup();*/ //Debug.Log("打开背包"); gb.SetActive(true); rc.GetComponent<iNum_Goods>().Grid_print(); }else { gb.SetActive(false); } } /// <summary> /// 物品 /// </summary> public void Goods() { //Debug.Log("打开物品背包"); if(back_gree.activeInHierarchy) { back_gree.SetActive(false); }else { back_gree.SetActive(true); } } /// <summary> /// 精灵 /// </summary> public void Sprits() { //Debug.Log("打开精灵背包"); if(back_spirits.activeInHierarchy) { back_spirits.SetActive(false); }else { back_spirits.SetActive(true); } } /// <summary> /// 时间 /// </summary> public void Time() { //游戏时间 } /// <summary> /// 道馆 /// </summary> public void Venue() { } /// <summary> /// 保存 /// </summary> public void Keep() { //连接数据库 } /// <summary> /// 退出 /// </summary> public void Goout() { //退出游戏 } }

对于脚本中的Goods方法,我们要在鼠标点击的时候触发,但我们希望的是打开菜单,点击相应的位置之后触发,所以我们开始写背包的脚本

定义一个脚本:Goods_grid(实现背包格子中的信息)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//该脚本我先引入了7种物品和一个空格子,作为物品反馈到玩家的背包中
public class Goods_Grid : MonoBehaviour { //0 空,1 苹果,2 金刚石,3 木炭,4 金珠,5 海星,6 化石,7 精灵球 public Sprite[] Goods; public int Grid_pc; //按钮 public Button Self; //角色 public GameObject player; // Use this for initialization
   //这里原本用了start函数来初始化背包,但是会出现bug,比如拾取的物品丢失,物品无限使用等,那只得调用一个线程,等后续有什么好的方法作者会进行优化,如有好的方法,可以在评论区评论
//项目经验 //(父级)start函数只会运行一次,不会因为物体的禁用或者启用而影响 void FixedUpdate () { Self.image.sprite = Goods[Grid_pc]; //iNum_Goods = new int[Goods.Length]; } /*private void OnMouseOver() { switch (Grid_pc) { case 1: Debug.Log("消息"); //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100), "剩下的苹果:可以恢复少量的体力。(一些精灵爱吃的食物)"); break; case 2: //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100)); break; case 3: //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100)); break; case 4: //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100)); break; case 5: //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100)); break; case 6: //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100)); break; case 7: //GUI.Box(new Rect(Input.mousePosition.x, Input.mousePosition.y, 100, 100)); break; default: break; } }*/ /// <summary> /// 点击物品格子后的方法 /// </summary> public void Onbace() { if(Grid_pc == 0) { Debug.Log("空格子"); return; }else { //根据Grid_pc判断是什么物品,并且调用相应的效果函数 //已修复(player不能使用预制体) //调用方法,使物品-1 //Debug.Log(player.GetComponent<iNum_Goods>().iNum[4]); player.GetComponent<iNum_Goods>().put_iNum(Grid_pc); //清除格子的图片 Self.GetComponent<Goods_Grid>().Grid_pc = 0; //清除最后一个格子的赘余 int rend = player.GetComponent<iNum_Goods>().rend_Button; Debug.Log(rend); player.GetComponent<iNum_Goods>().iNum_Button[rend].GetComponent<Goods_Grid>().Grid_pc = 0; } } }

当前我们的背包格子已经定义好了,但是我们的物品信息要怎样储存呢?

我原计划是想着可以存到back脚本里面,然后让格子挂载的脚本回调,这样不容易出现思路混乱的问题

但是在实际开发过程中,发现我对数据的把控不到位,改了又改,最终决定写一个新脚本,将它挂载到主角身上(player)

定义一个脚本:iNum_Goods(储存物品,并对物品的拾取和使用作出相应的数据更新)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class iNum_Goods : MonoBehaviour {

    //物品的数量
    public int[] iNum;

    public Button[] iNum_Button;

    public GameObject back_grid;

    //最后存放物品的格子
    public int rend_Button;

    public void Start()
    {
        //给背包分配空间
        int r = back_grid.GetComponentInChildren<Goods_Grid>().Goods.Length;
        iNum = new int[r];
    }
    /// <summary>
    /// 存入物品
    /// </summary>
    /// <param name="n">物品id</param>
    public void set_iNum(int n)
    {
        iNum[n]++;
    }
    /// <summary>
    /// 使用物品
    /// </summary>
    /// <param name="n">物品id</param>
    public void put_iNum(int n)
    {
        if(iNum[n] > 0)
        iNum[n]--;
    }
    public void Grid_print()
    { 
        int j = 0;
        for(int i = 0; i < iNum.Length; i++)
        {
            if(iNum[i] != 0)
            {
                iNum_Button[j].GetComponent<Goods_Grid>().Grid_pc = i;
                j++;
            }
        }
        rend_Button = j - 1;
    }
}

ok,背包系统开发完毕,下期继续更新~

原文地址:https://www.cnblogs.com/yylgoodjob/p/12736034.html