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、测试运行

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

相关推荐
星河耀银海4 小时前
Unity基础:UI组件详解:Toggle开关的状态控制
ui·unity·lucene
mxwin4 小时前
Unity URP 法线贴图:世界空间 vs 切线空间 深度解析两种法线贴图格式在实时渲染中的核心差异、适用场景与性能权衡
unity·游戏引擎·贴图
℡枫叶℡1 天前
Unity - 全局配置Unity工程的资源检索的目录
unity·资源检索配置
mxwin1 天前
Unity URP 下 TBN 矩阵学习 切线空间、tangent.w 与镜像 UV 的那些坑
学习·unity·矩阵·shader
程序猿多布1 天前
Unity导表工具解决方案-Luban使用教程
unity·luban
mxwin1 天前
Unity URP Shader 混合模式完全指南
unity·游戏引擎
mxwin1 天前
Unity URP 下 HDR 与 Tonemapping 的 Shader 意识
unity·游戏引擎
沉默金鱼1 天前
U3D高级编程:主程手记——第二章2.1读书笔记
unity·游戏引擎
mxwin2 天前
Unity Shader 深度写入与关闭ZWrite Off · 半透明排序 · 粒子穿插
unity·游戏引擎·shader
张老师带你学2 天前
宇宙飞船完整Unity项目
科技·游戏·unity·游戏引擎·模型