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

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

相关推荐
Sator122 分钟前
unity解决粒子与物体接触时的硬边缘问题
unity·游戏引擎
RPGMZ3 小时前
RPGMZ NPC头顶自动显示一段消息
前端·游戏引擎·rpgmz·rpgmakermz
程序员JerrySUN4 小时前
Jetson边缘嵌入式实战课程第三讲:L4T 与 Jetson 系统架构
linux·服务器·人工智能·安全·unity·系统架构·游戏引擎
萌萌的提莫队长6 小时前
Unity HDRP 渲染管线 Camera 输出到RenderTexture没有Alpha通道
unity·游戏引擎
winlife_6 小时前
Unity Editor 工具不该用反射写组件字段:SerializedObject 在 4 个场景里非用不可
unity·自动化·游戏引擎
星河耀银海6 小时前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene
郝学胜-神的一滴7 小时前
中级OpenGL教程 005:为球体&平面注入法线灵魂
c++·unity·图形渲染·three.js·opengl·unreal
那个村的李富贵7 小时前
unity编辑器工具,输出使用的字体
unity·编辑器·游戏引擎
游乐码1 天前
UnityGUI(五)GUI控件综合使用
开发语言·unity·c#
LF男男1 天前
TshitBullect.cs
unity