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

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

相关推荐
虾球xz9 小时前
游戏引擎学习第124天
java·学习·游戏引擎
Thomas_YXQ1 天前
Unity3D 战斗系统架构与设计详解
开发语言·unity·架构·系统架构·unity3d
Nicole Potter1 天前
内存泄漏指什么?常见的内存泄漏有哪些?
开发语言·游戏·unity·面试·c#
Jditinpc1 天前
Unity FBXExport导出的FBX无法在Blender打开
unity·游戏引擎·blender
虾球xz2 天前
游戏引擎学习第122天
学习·游戏引擎
Thinbug2 天前
UE(虚幻)学习(五)初学创建NPC移动和遇到的问题
学习·游戏引擎·虚幻
虾球xz2 天前
游戏引擎学习第123天
学习·游戏引擎
虾球xz2 天前
游戏引擎学习第121天
学习·游戏引擎
太妃糖耶2 天前
Unity地形系统
unity·游戏引擎
别偷喝船长的朗姆酒2 天前
【Unity】鱼群效果模拟
unity·游戏引擎