unity 2d入门飞翔小鸟按钮点击功能且场景切换(二)

1、素材包获取

链接: https://pan.baidu.com/s/1KgCtQ_7wt2mlbGbIaMVvmw

提取码: xxh8

2、将素材全部拉进去

3、创建新的场景

并且将场景添加到build settings里面

4、脚本

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class StartBtnLis : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    //监听鼠标按下
    private void OnMouseDown()
    {
    	//对象比例缩小
        transform.localScale = transform.localScale * 0.8f;
    }
    //监听鼠标松开
    private void OnMouseUp()
    {
    	//对象比例放大
        transform.localScale = transform.localScale / 0.8f;
        //场景切换
        SceneManager.LoadScene("game");
    }
}

5添加脚本

将c#脚本长按拉动到对应指定的图层就会把脚本添加进去

6、添加2d盒装碰撞器




7、测试运行

点击按钮则能看到按钮动态缩小并跳转到对应的场景

相关推荐
微三云生态系统架构师-彭丹15 小时前
任务卷轴积分系统架构设计:从任务状态机到合规风控的完整实现
unity·系统架构·游戏引擎
XR技术研习社17 小时前
从 PICO 文档看未来短期内的 Unity 版本选择
unity·游戏引擎·xr·vr
玖玥拾20 小时前
Unity 热更新(一)
unity·游戏引擎
软件黑马王子20 小时前
1.non-MonoBehaviour 单例模式泛型基类
unity·前端框架·c#
KhalilRuan1 天前
Unity性能优化
unity·性能优化·游戏引擎
ellis19701 天前
u3d IMGUI[二] 编辑器扩展
unity
五仁烧饼2 天前
Unity性能优化系列内存篇 - 移动端内存优化
unity·性能优化·游戏引擎
WiChP3 天前
【V0.1B15】从零开始的2D游戏引擎开发之路
游戏引擎
zhchyun20085 天前
# 【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(06)
ui·unity·游戏引擎
Behaviour5 天前
Unity游戏HybridCLR 热更新接入实战
游戏·unity·游戏引擎