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

愛在花開的季節  金牌会员 | 2025-1-24 20:22:28 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 879|帖子 879|积分 2637

预备



  • 创建Scenes场景,Scripts脚本,Prefabs预制体文件夹
修改背景颜色


  • 选中Main Camera

  • 找到背景

  • 选择颜色,一种白中透黄的颜色

创建小球


  • 将文件夹里的Circle拖入层级里

  • 选中Circle,位置为左右居中,偏上,颜色为黑色,大小缩为0.7


分数


  • 创建Text

  • 删撤除EventSystem,因为本例中UI不必要做任何事件

  • 选中Text,点击重置,文本居中,颜色为白色,内容为0



  • 选中Canvas,将渲染模式改为世界空间,接着修改大小,改为100.100



  • 将缩放改为0.01,拖动到小球上

  • 使得Circle和Canvas的位置坐标同等,都为0,2,0

  • 选择MainCamera设置为Canvas的事件摄像机

小球活动


  • 创建一个脚本,选择MonoBehaviour,定名为RotateSelf

  • 将此脚本挂载到Circle的下面

  • 编写脚本
  1. using JetBrains.Annotations;
  2. using UnityEngine;
  3. public class NewMonoBehaviourScript : MonoBehaviour
  4. {
  5.     public float speed = 90;
  6.     // Start is called once before the first execution of Update after the MonoBehaviour is created
  7.     void Start()
  8.     {
  9.         
  10.     }
  11.     // Update is called once per frame
  12.     void Update()
  13.     {
  14.         transform.Rotate(new Vector3(0, 0, speed * Time.deltaTime));
  15.     }
  16. }
复制代码

  • 在场景中点击播放,可以看到Circle在逆时针旋转,如果想要顺时针旋转,在speed前加一个负号

针头


  • 将针导入到层级里,将Pin的大小适当放大



  • 制作针的尾部,复制一个Circle

  • 调整大小位置颜色



  • 将Pin拖入Prefabs文件夹里,方便举行实例化创建

  • 给针头添加碰撞器,选中针头,在检查器底下的添加组件,搜Circle Collider 2D添加


生成针


  • 创建两个空对象,将第一个定名为StartPosition

  • 将Pin放到StartPosition的下面,如许可以举行预览,调整位置



  • 将StartPosition复制,拖到屏幕外面举行实例化



  • 然后删去针,改名为SpawnPositon

  • 创建一个空对象,定名为GameManager

  • 创建一个GameManager脚本,挂载到对象下面
  1. using UnityEngine;
  2. public class GameManager : MonoBehaviour
  3. {
  4.     private Transform startPosition;
  5.     private Transform spawnPosition;
  6.     public GameObject pinPrefab;
  7.     // Start is called once before the first execution of Update after the MonoBehaviour is created
  8.     void Start()
  9.     {
  10.         startPosition = GameObject.Find("StartPosition").transform;
  11.         spawnPosition = GameObject.Find("SpawnPosition").transform;
  12.         SpawnPin();
  13.     }
  14.     // Update is called once per frame
  15.     void Update()
  16.     {
  17.         
  18.     }
  19.     void SpawnPin()
  20.     {
  21.         GameObject.Instantiate(pinPrefab, spawnPosition.position, pinPrefab.transform.rotation);
  22.     }
  23. }
复制代码

  • 将PIn实例拖到右边的Pin Prefab里

  • 点击运行后屏幕外生成了针


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

愛在花開的季節

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表