Unity2D游戏开发-Pak木鱼

7 篇文章 0 订阅
6 篇文章 0 订阅

在接下来文章里我会以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:塞反了改一下)

 完工

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小唐C++

干累了,给个吧,求求了

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值