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

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

相关推荐
虾球xz16 小时前
游戏引擎学习第210天
学习·游戏引擎
维度攻城狮18 小时前
高效创建工作流,可实现类似unreal engine的蓝图效果,内部使用多线程高效执行节点函数
python·游戏引擎·开源软件·虚幻·graph·工作流
浅陌sss20 小时前
设计模式 --- 原型模式
unity·游戏引擎
21 小时前
Unity中基于2.5D的碰撞系统
unity·游戏引擎
scott.cgi1 天前
「Unity3D」TextMeshPro中的TMP_InputField,用来实现输入框的几个小问题
unity·ugui·textmeshpro·tmp_inputfield·inputfield·inputfield输入框·ugui输入框
虾球xz1 天前
游戏引擎学习第212天
c++·学习·游戏引擎
虾球xz1 天前
游戏引擎学习第209天
学习·游戏引擎
蔗理苦2 天前
2025-04-08 NO.4 Quest3 交互教程
unity·交互·vr·quest
郭逍遥2 天前
[Godot] C#简单实现人物的控制和动画
游戏引擎·godot
我有医保我先冲2 天前
智能仓储数字孪生Demo(Unity实现)
unity·游戏引擎