unity实现打飞碟游戏

本文详细介绍了使用Unity引擎开发打飞碟游戏的流程,包括disk对象、Ruler属性类、DiskController单例控制、Singleton模式以及游戏逻辑。通过预加载资源、随机属性生成、碰撞检测和UI记分板实现,讲解了整个游戏的实现细节和技术要点。
摘要由CSDN通过智能技术生成

流程总览

以下段落是按照自己在编写该程序时的先后顺序安排的,该程序可以在该github地址找到,有兴趣可以download下来跑一跑:打飞碟小游戏
游戏画面

disk(飞碟对象)

首先需要制作飞碟的预制件(prefeb),觉得省事的话可以创建一个球体或者胶囊对象然后调整它的Y轴scale,将它压扁成飞碟状。
我的做法采取了将两个对象放置在一个父的空对象上,并将父对象称作disk:

对象总览
飞碟模型

Ruler(每个disk独有的属性保存类)

public class Ruler
{
   
    public float size;
    public Color color;
    public int score;
    public Vector3 position;
    public Vector3 direction;
    public float speed;

    public Ruler(float size, Color color, Vector3 position, Vector3 direction, float speed)
    {
   
        this.size = size;
        this.color = color;
        this.position = position;
        this.direction = direction;
        this.speed = speed;
        this.score = (int)(this.speed + this.size);
    }
}

Ruler类是一个放置在DiskData文件内的并被DiskData类所依赖的一个公有类,
它实际上承担了disk对象的所有属性,包括:
颜色(Color),大小(float),速度(float),位置(Vector3),力(Vector3),分数(int)。
通过构造函数来生成某个disk的所有属性,然后再通过DiskData对象的set方法来为挂载该脚本的disk对象设置相关属性。

public class DiskData : MonoBehaviour
{
   
    Ruler _ruler;
    public Ruler ruler
    {
   
        get
        {
   
            return _ruler;
        }
        set
        {
   
            _ruler = value;
            this.gameObject.GetComponent<Transform>().position = value.position;
            this.gameObject.GetComponent<Transform>().localScale = new Vector3(1, 1, 1) * value.size;
            this.gameObject.transform.GetChild(0).gameObject.GetComponent<Renderer>().material.color = value.color;
        }
    }</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值