unity 模仿东方弹幕游戏

首先感谢我们组的两位大佬,认真负责又很有耐心地指导我们,跟着他们学到了不少东西。

先设计好初稿,然后再分析实现步骤,比如列出数学物理公式,最后就是编码实现阶段了。下面是我的代码:

BulletCenterDance:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletCenterDance : BulletTypeB {

    public Vector2 Valocity;
    
    // Update is called once per frame
    void Update () {
        transform.Translate(Valocity * Time.deltaTime);
    }
}

RevolveCircle:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RevolveCircle : SpellCard {

    public RevolveCircle() : base(new Circle(), new Vector2(-1.5f, 2.4f), 78f, 15000, "想起「旋转圆舞」 ")
    {
    }
}

class Circle : State<Boss>{
    float time = 2f;
    float timeC = 4f;
    float t = -4f;
    GameObject Revolve;
    public override void Enter(Boss owner)
    {
        Revolve  = ((Satori)owner).RevolveCircleResources.GetComponent<RevolveCircleResource>().RevolveCircle;
        owner.transform.position = new Vector3(-1.53f, 0, 0);
    }
    public override void Execute(Boss owner)
    {
        timeC -= Time.deltaTime;
        time -= Time.deltaTime;
        t += Time.deltaTime;
        if (time < 0) {
            time += 0.1f;
            Vector2 StartLo;
            if (GameManager.player != null) {
                StartLo = GameManager.player.transform.position - owner.transform.position;
            } else {
                StartLo = new Vector2 (0, 1);
            }
            StartLo.Normalize ();
            for (int i = -1; i <= 1; i++) {
                float routeAngle = 30 * Mathf.Deg2Rad * i;
                Vector2 valocity = new Vector2(StartLo.x*Mathf.Cos(routeAngle)-StartLo.y*Mathf.Sin(routeAngle),StartLo.x*Mathf.Sin(routeAngle)+StartLo.y*Mathf.Cos(routeAngle));
                valocity *= 3.0f;
                BulletCenterDance c = GameObject.Instantiate (((Satori)owner).RevolveCircleResources.GetComponent<RevolveCircleResource> ().RevolveCircle, owner.transform.position, Quaternion.identity).GetComponent<BulletCenterDance> ();
                c.Valocity = valocity;
                GameObject.Destroy (c.gameObject, 5f);
            }



        }
        if (timeC<0) {
            timeC += 0.3f;
            for (int i = 0; i < 4; i++) {
                Vector2 StartLocation = new Vector2 (Mathf.Cos (t), Mathf.Sin (t));
                Vector2 valocity = new Vector2 (2f * Mathf.Cos (2f * t + i * Mathf.PI / 2), 2f * Mathf.Sin (2f * t + i * Mathf.PI / 2));
                BulletCenterDance r = GameObject.Instantiate (((Satori)owner).RevolveCircleResources.GetComponent<RevolveCircleResource> ().BulletTriangle, owner.transform.position + (Vector3)StartLocation, Quaternion.identity).GetComponent<BulletCenterDance> ();
                r.Valocity = valocity;
                GameObject.Destroy (r.gameObject, 10f);
            }
            for (int i = 0; i < 4; i++) {
                Vector2 StartLocation = new Vector2 (-Mathf.Cos (t), Mathf.Sin (t));
                Vector2 valocity = new Vector2 (-2f * Mathf.Cos (2f * t + i * Mathf.PI / 2), 2f * Mathf.Sin (2f * t + i * Mathf.PI / 2));
                BulletCenterDance r = GameObject.Instantiate (((Satori)owner).RevolveCircleResources.GetComponent<RevolveCircleResource> ().BulletTriangle, owner.transform.position + (Vector3)StartLocation, Quaternion.identity).GetComponent<BulletCenterDance> ();
                r.Valocity = valocity;
                GameObject.Destroy (r.gameObject, 10f);
            }
        }
    }
            


}


RevolveCircleResources:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RevolveCircleResource : MonoBehaviour {

    public GameObject RevolveCircle; //
    public GameObject BulletTriangle; //
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

转载于:https://www.cnblogs.com/1997Ff/p/7498400.html

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值