123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using Adon.Game.BO;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace AdonGameKit
- {
- /// <summary>
- /// 言灵射线
- /// </summary>
- public class YLBeamAdon : MonoBehaviour
- {
- RaycastHit hitPoint;
- /// <summary>
- /// 最大射线长度
- /// </summary>
- public float MaxBeamLength = 30;
- public LayerMask layerMask;
- /// <summary>
- /// 射线对象
- /// </summary>
- public Transform rayBeam;
- /// <summary>
- /// 冲击效果对象
- /// </summary>
- public Transform rayImpact;
- /// <summary>
- /// 枪口效果对象
- /// </summary>
- public Transform rayMuzzle;
- public Transform hitEff;
- public BaseYLPartAdon m_YL;//释放者挂件(言灵)
- public BaseHero m_Hero;//释放者(英雄)
- public float m_FireTimeMax = 0.5f;
- public string m_CurUseSkill;
- float beamLength;
- bool isFXSpawned = false; // 碰撞光效只生产一次
- float fireTime;
- //Transform newRayBeam;
- void Awake()
- {
- fireTime = m_FireTimeMax;
- //hitEff = transform.Find("Monster_Trajectend");
- rayBeam = transform.Find("Monster_Traject");
- layerMask = 1 << LayerMask.NameToLayer("Enemy");
- }
- // Start is called before the first frame update
- void Start()
- {
- //newRayBeam = Instantiate(rayBeam);
- //newRayBeam.gameObject.SetActive(false);
- fireTime = m_FireTimeMax;
- hitEff.gameObject.SetActive(false);
- }
- void FixedUpdate()
- {
- Raycast();
- }
- void Raycast()//射线
- {
- hitPoint = new RaycastHit();
- Ray ray = new Ray(transform.position, transform.forward);//射线
- if (Physics.Raycast(ray, out hitPoint, MaxBeamLength, layerMask))//如果射线有碰撞
- {
- beamLength = Vector3.Distance(transform.position, hitPoint.point);//根据距离算得射线长度
- rayBeam.transform.localScale = new Vector3(1,1, beamLength);
- if (rayImpact)//冲击效果位置
- {
- rayImpact.position = hitPoint.point + transform.forward * 0.1f;
- rayImpact.gameObject.SetActive(true);
- }
-
- DefendMonster defend = hitPoint.transform.GetComponent<DefendMonster>();
- if (defend != null)
- {
- Debug.Log("打中了防御罩");
- //计时,周期发送伤害
- if (fireTime >= m_FireTimeMax)
- {
- fireTime = 0;
- //实例化克隆防御光效
- Transform effobj = Instantiate(defend.m_DefendHitObj);
- effobj.gameObject.AddComponent<DestroyObjectDelayed>();
- effobj.position = hitPoint.point;//设置爆炸位置
- effobj.gameObject.SetActive(true);
- Transform effobj2 = Instantiate(hitEff);
- effobj2.gameObject.AddComponent<DestroyObjectDelayed>();
- effobj2.position = hitPoint.point;//设置爆炸位置
- effobj2.gameObject.SetActive(true);
- }
- }
- else
- {
- //newRayBeam.gameObject.SetActive(true);
- //计时,周期发送伤害
- if (fireTime >= m_FireTimeMax)
- {
- fireTime = 0;
- //if (!isFXSpawned)//执行一次
- //{
- //isFXSpawned = true;
- BaseMonsterAdon component = hitPoint.transform.GetComponent<BaseMonsterAdon>();
- if (component != null)
- {
- Transform effobj2 = Instantiate(hitEff);
- effobj2.gameObject.AddComponent<DestroyObjectDelayed>();
- effobj2.position = hitPoint.point;//设置爆炸位置
- effobj2.gameObject.SetActive(true);
- //发送伤害消息
- //返回false能量不足,打断技能
- bool bo = X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill(
- m_Hero.mData.UID, m_CurUseSkill,
- true, m_YL.M_YLType, component.mData.UID, false);
- if (bo == false)
- {
- m_YL.m_CurUseSkill = "";
- m_YL.OffFire();
- }
- }
- }
-
- }
- fireTime += Time.deltaTime;
- }
- else
- {
- hitEff.gameObject.SetActive(false);
- //newRayBeam.gameObject.SetActive(false);
- // 设置射线为最大长度
- beamLength = MaxBeamLength;
- rayBeam.transform.localScale = new Vector3(1, 1, beamLength);
- //lineRenderer.SetPosition(1, new Vector3(0f, 0f, beamLength));
- //设置爆炸位置
- if (rayImpact)
- rayImpact.position = transform.position + transform.forward * beamLength;
- }
- //设置枪口光效位置
- if (rayMuzzle)
- rayMuzzle.position = transform.position + transform.forward * 0.1f;
- }
- }
- }
|