123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using Adon.Game.BO;
- using Adon.Game.Helper;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace AdonGameKit
- {
- /// <summary>
- /// 言灵距离形子弹
- /// </summary>
- public class YLDistanceBulletAdon : MonoBehaviour
- {
- /// <summary>
- /// 子弹步进速度
- /// </summary>
- public float m_Velocity = 10;
- /// <summary>
- /// 子弹最大距离
- /// </summary>
- public float m_DistanceMax = 10;
- /// <summary>
- /// 攻击距离
- /// </summary>
- public float m_AttackRange = 5;
- /// <summary>
- /// 生命周期
- /// </summary>
- public float m_LifeTime = 2f;
- public BaseYLPartAdon m_YL;//释放者挂件(言灵)
- public BaseHero m_Hero;//释放者(英雄)
- public string m_CurUseSkill;
- public Transform m_HitEff;//受击光效
- /// <summary>
- /// 子弹当前距离
- /// </summary>
- private float curDistance = 0;
- bool isFXSpawned = false; // 碰撞光效只生产一次
- float timer = 0f; // 子弹生命周期计时
- void Awake()
- {
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- void FixedUpdate()
- {
- //计算距离,达到距离则悬停,添加开启碰撞检测
- if (!isFXSpawned)//执行一次
- {
- if (curDistance < m_DistanceMax)//距离计算
- {
- Vector3 step = transform.forward * Time.deltaTime * m_Velocity;//子弹步进
- curDistance += Vector3.Distance(transform.position, (transform.position + step));//距离增加
- transform.position += step;//向前步进
- }
- else
- {
- //达到距离则执行攻击
- isFXSpawned = true;
- //查找周围敌人
- List<GameObject> monsters = PlayerHelperAdon.GetNearEnemysDistance(this.gameObject, m_AttackRange);
- for (int i = 0; i < monsters.Count; i++)
- {
-
- BaseMonsterAdon component = monsters[i].gameObject.GetComponent<BaseMonsterAdon>();
- //发送伤害消息
- X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill(m_Hero.mData.UID, m_YL.m_CurUseSkill, true, m_YL.M_YLType, component.mData.UID, false);
- //释放受击效果
- Transform hitEffObj = Instantiate(m_HitEff);
- hitEffObj.gameObject.SetActive(true);
- hitEffObj.position = component.m_HitObj.position;
- hitEffObj.LookAt(transform.position);
- hitEffObj.eulerAngles = new Vector3(0,hitEffObj.eulerAngles.y-180,0);
- //hitEffObj.rotation = Quaternion.Euler(component.transform.position - transform.position);
- //hitEffObj.LookAt(transform);
- if (!hitEffObj.GetComponent<DestroyObjectDelayed>()) hitEffObj.gameObject.AddComponent<DestroyObjectDelayed>();//添加延迟销毁脚本
- }
- }
-
- }
- // 生命周期到了则销毁
- if (timer >= m_LifeTime)
- OnProjectileDestroy();
- timer += Time.deltaTime;
- }
- /// <summary>
- /// 子弹销毁
- /// </summary>
- void OnProjectileDestroy()
- {
- //销毁,后期改为对象池
- Destroy(this.gameObject);
- }
- }
- }
|