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

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

相关推荐
avi91112 天前
发现一个宝藏Unity开源AVG框架,视觉小说的脚手架
unity·开源·框架·插件·tolua·avg
一线灵2 天前
跨平台游戏引擎 Axmol-2.10.0 发布
游戏引擎
沉默金鱼3 天前
Unity实用技能-格式化format文字
ui·unity·游戏引擎
jyy_993 天前
通过网页地址打开unity的exe程序,并传参
unity
qq_205279053 天前
Unity TileMap 使用经验
unity·游戏引擎
心灵宝贝3 天前
Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
macos·unity·游戏引擎
TO_ZRG3 天前
Unity SDK 通过 Registry 分发及第三方依赖处理指南
unity·游戏引擎
7***n754 天前
C++在游戏中的Cocos2d-x
游戏·游戏引擎·cocos2d
龙智DevSecOps解决方案4 天前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce
Y***K4344 天前
C在游戏中的Godot
游戏·游戏引擎·godot