预备
- 创建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的下面
- 编写脚本
- using JetBrains.Annotations;
- using UnityEngine;
- public class NewMonoBehaviourScript : MonoBehaviour
- {
- public float speed = 90;
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- void Start()
- {
-
- }
- // Update is called once per frame
- void Update()
- {
- transform.Rotate(new Vector3(0, 0, speed * Time.deltaTime));
- }
- }
复制代码
- 在场景中点击播放,可以看到Circle在逆时针旋转,如果想要顺时针旋转,在speed前加一个负号
针头
- 制作针的尾部,复制一个Circle
- 调整大小位置颜色
- 将Pin拖入Prefabs文件夹里,方便举行实例化创建
- 给针头添加碰撞器,选中针头,在检查器底下的添加组件,搜Circle Collider 2D添加
生成针
- 创建两个空对象,将第一个定名为StartPosition
- 将Pin放到StartPosition的下面,如许可以举行预览,调整位置
- 将StartPosition复制,拖到屏幕外面举行实例化
- 然后删去针,改名为SpawnPositon
- 创建一个空对象,定名为GameManager
- 创建一个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 created
- void Start()
- {
- startPosition = GameObject.Find("StartPosition").transform;
- spawnPosition = GameObject.Find("SpawnPosition").transform;
- SpawnPin();
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- void SpawnPin()
- {
- GameObject.Instantiate(pinPrefab, spawnPosition.position, pinPrefab.transform.rotation);
- }
- }
复制代码
- 将PIn实例拖到右边的Pin Prefab里
- 点击运行后屏幕外生成了针
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |