unity3d:弹道飞行

敌人间隔5-10s开枪,有子弹从我眼前飞过,粒子使用lean缓冲池循环使用

敌人:

using Lean.Pool;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GunEffectCtrl : MonoBehaviour {
    public Transform m_bornTrans;
    public Transform m_toTrans;

    public LeanGameObjectPool m_poolDanDao;
    public LeanGameObjectPool m_poolQiangKou;

    public float m_nextMin = 5;
    public float m_nextMax = 10;
    float m_nextTime = 1; 
    float m_time = 0;
    // Use this for initialization
    void Start () {
        m_time = Time.time;
        m_nextTime = Time.time + (float)Random.Range(m_nextMin, m_nextMax);

    }
	
	// Update is called once per frame
	void Update () {
        m_time += Time.deltaTime;
        if (m_time >= m_nextTime)
        {
            m_nextTime = Time.time + (float)Random.Range(m_nextMin, m_nextMax);
            Fire();
        }
	}


    void Fire()
    {
        Vector3 dir = m_toTrans.position - m_bornTrans.position;
        

        GameObject danDao = m_poolDanDao.Spawn(m_bornTrans.position, m_bornTrans.rotation);
        danDao.transform.forward = dir.normalized;
        GameObject qiangKou = m_poolQiangKou.Spawn(m_bornTrans.position, m_bornTrans.rotation);
        //PublicFunc.PlayParticle(qiangKou.transform);

        if (danDao.GetComponent<DanDaoFlyCtrl>() == null)
        {
            danDao.AddComponent<DanDaoFlyCtrl>();
        }

        danDao.GetComponent<DanDaoFlyCtrl>().SetInfo(m_toTrans, 15);
    }


    void OnDrawGizmos()
    {
       
        // color depends on status
        Color c = Color.white;
        
       
       Debug.DrawLine(m_bornTrans.position, m_toTrans.position, c);
    }
}

弹道粒子飞行

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

public class DanDaoFlyCtrl : MonoBehaviour {
    Transform m_trans;
    bool m_isSet = false;
    Transform m_toTrans;
    float m_speed;
	// Use this for initialization
	void Start () {
        m_trans = this.transform;

    }

    public void SetInfo(Transform toTrans, float speed)
    {
        m_toTrans = toTrans;
        m_speed = speed;
        m_isSet = true;
    }
	// Update is called once per frame
	void Update () {
        if (m_isSet == true)
        {
            m_trans.Translate(Vector3.forward * Time.deltaTime * m_speed); 

            //m_trans.position = Vector3.MoveTowards(m_trans.position, m_toTrans.position, Time.deltaTime * m_speed);
        }
    }

    private void OnDisable()
    {
        m_isSet = false;
    }
}

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

四夕立羽

你的鼓励将是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值