当前位置: 首页 > article >正文

Unity2D游戏开发-Pak木鱼

在接下来文章里我会以Unity为主一起制作游戏

在unity 里如何制作一个简单的敲木鱼游戏?

创建一个2D场景(本人使用Unity2023)

(每个一段时间要申请一个个人许可证)

点击下方蓝色按钮创建

将以下素材拖动到Assets文件夹中

这张图随意命名我先叫他背景

 单机左键,将该图的纹理改为Sprite(2D和UI)

 在同层级中右键创建 C#脚本

右键重命名将名字改为 fishicommand 

单击场景中的Main Camera (就是摄像机)将创建好的C#脚本添加(拖动到添加组件)

 (注意:请检查你的摄像机又没有Audio Listener组件)

如果没有,点击添加组件并搜索Audio Listener添加

这样就行

双击在 Assets文件夹中 的C#脚本复制下面的代码并ctrl+S 保存

(别问我为啥不写协程)

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

public class fishicommand : MonoBehaviour
{
    public GameObject e2;
    public RectTransform uiElement;
    public RectTransform uiElement1;
    public Text text_;
    public GameObject GameObject1;
    public GameObject GameObject2;
    public Vector3 vector3xyz = new Vector3(0, 0, 0);
    public int fishgongde = 1;
    public int biaoji = 1;
    public bool textshangshen = false;
    public float xyz_y = 750;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (e2 != null)

        {
            e2.transform.position = new Vector3(0, uiElement1.localPosition.y / 650, 0);
        }
        text_.text = fishgongde.ToString("000");
        uiElement1.localPosition = new Vector3(255, xyz_y, 0);
        if (Input.GetMouseButtonDown(0))
        {
            GameObject e1 = Instantiate(GameObject2.gameObject, vector3xyz, this.transform.rotation);
            Destroy(e1, 1.25f);
            if (!textshangshen) xyz_y = -1000;
            fishgongde++; textshangshen = true;
            uiElement.localPosition = new Vector3(0,-350, 0);
        }
        if (uiElement.localPosition.y < 0)
        {
            uiElement.localPosition = new Vector3(0, uiElement.localPosition.y + 400 * Time.deltaTime);
        }
        if (fishgongde % 15 == 0 && biaoji != fishgongde)
        {
            e2 = Instantiate(GameObject1.gameObject, vector3xyz, this.transform.rotation);
            Destroy(e2, 5f);
            biaoji = fishgongde;
        }
        if (textshangshen)
        {
            xyz_y += 1500 * Time.deltaTime;
            if (xyz_y >= 300) textshangshen = false;
        }
        if (!textshangshen) xyz_y = 300;
    }
}

接下来设置UI

创建一个UI图片随便命名这里命名为 Image 1

点击Canvas像我这样:设制 

把屏幕缩放比例改成9:16(没有的画要自己添加)

改背景颜色(推荐改成黑色)

 调整木鱼图标将缩放改为stretch 并选择保持长宽比并将数值清零 

创建3个旧版text并这样设置(文本按名字设置并放在合适位置)

 

创建两个空对象将他们放入脚本

 导入一个敲木鱼的声音并放咋空对项1中(要添加音频组件)

 再制作一个特效为第二个添加(添加为子文件)随便做

制作成预制体塞进去(ps:塞反了改一下)

 完工


http://www.kler.cn/a/282114.html

相关文章:

  • Module not found: Can‘t resolve ‘tls‘/Module not found: Can‘t resolve ‘net‘
  • (十三)Flink SQL
  • 【自由能系列(中级)】自由能与变分自由能——从状态到配置的效益最大化
  • 手机游玩植物大战僵尸杂交版V2.3.7最新版教程(文章末尾免费直接下载链接)
  • 【Java】—— Java面向对象进阶:Java银行账户管理系统设计与实现
  • 分布式数据一致性小结
  • 【爬虫采集工具】用python开发的快手评论区采集软件
  • 单片机原理及技术(八)—— 串行口的工作原理及应用
  • 墨者学院 手工注入题解(oracle数据库)
  • 华为2016校园招聘上机笔试题
  • 取模+背包
  • 【Word与WPS如何冻结首行首列及窗口】
  • Linux常见基础命令
  • 责任链模式-升级版
  • python办公自动化:使用`Python-PPTX`进行文本框和段落操作
  • Python统计FreeMind测试用例数量
  • 【办公类-54-03】20240828班级点名册模版(双休国定假涂成灰色)
  • 网络层 I(网络层的功能)【★★★★★★】
  • wpf prism 《1》、区域 、模块化
  • 2024 年顶级 Flutter UI 框架和库