游戏界面:

游戏实现思路:
游戏开始随机生成5个Box
键盘输入控制Player移动 当Player碰撞到物体 检测物体身上标签
如果Tag为Box则Box销毁 在其位置生成一个Gold
如果Tag为Gold则Gold销毁 得分+1
游戏实现过程:
所需物体: Box Gold(Prefabs)用于实例化、Player、Text(计算得分)CreatBOx(空物体,控制Box生成)
所需脚本:
Gold 挂载在预制体Gold上,实现金币自动旋转
using UnityEngine;
using System.Collections;
public class Gold : MonoBehaviour {
private Transform transform;
void Start () {
transform = gameObject.GetComponent<Transform>();
}
void Update () {
//使物体旋转
transform.Rotate(Vector3.left,5);
}
}
Box 挂载在预制体Box上 实现物体生成后3-5s内销毁
using UnityEngine;
using System.Collections;
public class Box : MonoBehaviour {
// Use this for

本文介绍了一款使用Unity开发的小游戏,游戏中通过键盘控制Player移动,当与物体发生碰撞时,根据物体标签进行不同操作:碰撞到Box则Box消失,替换为Gold;碰撞到Gold则得分增加,Gold消失。游戏涉及的关键技术包括Prefab实例化、碰撞检测、物体旋转、自动销毁和得分计算。
最低0.47元/天 解锁文章
1万+





