当前位置: 首页 > news >正文

Unity|小游戏复刻|见缝插针1(C#)

准备

![[Pasted image 20250123001920.png]]

  1. 创建Scenes场景,Scripts脚本,Prefabs预制体文件夹
修改背景颜色
  1. 选中Main Camera
    ![[Pasted image 20250123002236.png]]

  2. 找到背景
    ![[Pasted image 20250123002319.png]]

  3. 选择颜色,一种白中透黄的颜色
    ![[Pasted image 20250123002353.png]]

创建小球
  1. 将文件夹里的Circle拖入层级里
    ![[Pasted image 20250123002543.png]]

  2. 选中Circle,位置为左右居中,偏上,颜色为黑色,大小缩为0.7
    ![[Pasted image 20250123002729.png]]

![[Pasted image 20250123002928.png]]

分数
  1. 创建Text
    ![[Pasted image 20250123003014.png]]

  2. 删除掉EventSystem,因为本例中UI不需要做任何事件
    ![[Pasted image 20250123003233.png]]

  3. 选中Text,点击重置,文本居中,颜色为白色,内容为0
    ![[Pasted image 20250123003330.png]]

![[Pasted image 20250123003522.png]]

  1. 选中Canvas,将渲染模式改为世界空间,接着修改大小,改为100.100
    ![[Pasted image 20250123003619.png]]

![[Pasted image 20250123003850.png]]

  1. 将缩放改为0.01,拖动到小球上
    ![[Pasted image 20250123004104.png]]

  2. 使得Circle和Canvas的位置坐标一致,都为0,2,0
    ![[Pasted image 20250123004307.png]]

  3. 选择MainCamera设置为Canvas的事件摄像机
    ![[Pasted image 20250123004752.png]]

小球运动
  1. 创建一个脚本,选择MonoBehaviour,命名为RotateSelf
    ![[Pasted image 20250123005342.png]]

  2. 将此脚本挂载到Circle的下面
    ![[Pasted image 20250123011624.png]]

  3. 编写脚本

using JetBrains.Annotations;
using UnityEngine;public class RotateSelf : MonoBehaviour
{public float speed = 90;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){}// Update is called once per framevoid Update(){transform.Rotate(new Vector3(0, 0, speed * Time.deltaTime));}
}
  1. 在场景中点击播放,可以看到Circle在逆时针旋转,如果想要顺时针旋转,在speed前加一个负号
    ![[Pasted image 20250123011609.png]]
针头
  1. 将针导入到层级里,将Pin的大小适当放大
    ![[Pasted image 20250123012934.png]]

![[Pasted image 20250123012940.png]]

  1. 制作针的尾部,复制一个Circle
    ![[Pasted image 20250123013315.png]]

  2. 调整大小位置颜色
    ![[Pasted image 20250123013335.png]]

![[Pasted image 20250123013353.png]]

  1. 将Pin拖入Prefabs文件夹里,方便进行实例化创建
    ![[Pasted image 20250123013620.png]]

  2. 给针头添加碰撞器,选中针头,在检查器底下的添加组件,搜Circle Collider 2D添加
    ![[Pasted image 20250123013708.png]]

![[Pasted image 20250123013750.png]]

生成针
  1. 创建两个空对象,将第一个命名为StartPosition
    ![[Pasted image 20250123014250.png]]

  2. 将Pin放到StartPosition的下面,这样可以进行预览,调整位置
    ![[Pasted image 20250123014347.png]]

![[Pasted image 20250123014223.png]]

  1. 将StartPosition复制,拖到屏幕外面进行实例化
    ![[Pasted image 20250123014450.png]]

![[Pasted image 20250123014530.png]]

  1. 然后删去针,改名为SpawnPositon
    ![[Pasted image 20250123014640.png]]

  2. 创建一个空对象,命名为GameManager
    ![[Pasted image 20250123014806.png]]

  3. 创建一个GameManager脚本,挂载到对象下面

using UnityEngine;public class GameManager : MonoBehaviour
{private Transform startPosition;private Transform spawnPosition;public GameObject pinPrefab;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){startPosition = GameObject.Find("StartPosition").transform;spawnPosition = GameObject.Find("SpawnPosition").transform;SpawnPin();}// Update is called once per framevoid Update(){}void SpawnPin(){GameObject.Instantiate(pinPrefab, spawnPosition.position, pinPrefab.transform.rotation);}
}
  1. 将PIn实例拖到右边的Pin Prefab里
    ![[Pasted image 20250123015728.png]]

  2. 点击运行后屏幕外生成了针
    ![[Pasted image 20250123020249.png]]

http://www.lryc.cn/news/526840.html

相关文章:

  • No.1|Godot|俄罗斯方块复刻|棋盘和初始方块的设置
  • SSM框架探秘:Spring 整合 SpringMVC 框架
  • 2025.1.20——二、buuctf BUU UPLOAD COURSE 1 1 文件上传
  • 【架构面试】三、高可用高性能架构设计
  • 11.渲染管线——光栅化阶段
  • 【数据分享】1929-2024年全球站点的逐月平均能见度(Shp\Excel\免费获取)
  • 二叉树的深度
  • MySQL命令及用法(精华版)
  • R语言学习笔记之高效数据操作
  • 将 OneLake 数据索引到 Elasticsearch - 第二部分
  • Linux——冯 • 诺依曼体系结构
  • Java进阶(一)
  • appium自动化环境搭建
  • Qt 5.14.2 学习记录 —— 이십 QFile和多线程
  • 積分方程與簡單的泛函分析7.希爾伯特-施密特定理
  • 使用vitepress搭建自己的博客项目
  • 开始步入达梦中级dba
  • 如何在docker中的mysql容器内执行命令与执行SQL文件
  • S4 HANA更改Tax base Amount的字段控制
  • Linux权限有关
  • 【github 使用相关】提交pr和commit message Conventional Commits 规范 代码提交的描述该写什么?
  • Docker—搭建Harbor和阿里云私有仓库
  • Maven的下载安装配置
  • Rust:高性能与安全并行的编程语言
  • matlab的cat()函数详解(OK)
  • 将个人微信中的时间改成标准的日期时间格式
  • centos9编译安装opensips 二【进阶篇-定制目录+模块】推荐
  • 初步搭建并使用Scrapy框架
  • 基于SpringBoot的软件产品展示销售系统
  • pycharm 运行远程环境问题 Error:Failed to prepare environment.