using Adon.Game.BO; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace AdonGameKit { /// /// 言灵射线 /// public class YLBeamAdon : MonoBehaviour { RaycastHit hitPoint; /// /// 最大射线长度 /// public float MaxBeamLength = 30; public LayerMask layerMask; /// /// 射线对象 /// public Transform rayBeam; /// /// 冲击效果对象 /// public Transform rayImpact; /// /// 枪口效果对象 /// 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(); if (defend != null) { Debug.Log("打中了防御罩"); //计时,周期发送伤害 if (fireTime >= m_FireTimeMax) { fireTime = 0; //实例化克隆防御光效 Transform effobj = Instantiate(defend.m_DefendHitObj); effobj.gameObject.AddComponent(); effobj.position = hitPoint.point;//设置爆炸位置 effobj.gameObject.SetActive(true); Transform effobj2 = Instantiate(hitEff); effobj2.gameObject.AddComponent(); 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(); if (component != null) { Transform effobj2 = Instantiate(hitEff); effobj2.gameObject.AddComponent(); 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; } } }