Bullet2601001_1.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Adon.Game.BO;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace AdonGameKit
  6. {
  7. /// <summary>
  8. /// Bullet2601001_1子弹(抛物线)
  9. /// </summary>
  10. public class Bullet2601001_1 : MonoBehaviour
  11. {
  12. public BaseMonsterAdon m_BaseMonsterAdon;
  13. private Vector3 bulletDir = Vector3.zero;
  14. private int skillIndex = 0;
  15. public float speed = 10;
  16. private float distanceToTarget;
  17. private Vector3 targetPos;
  18. public void SetMonster(BaseMonsterAdon monster, Vector3 dir, int _skillIndex, Vector3 _targetPos)
  19. {
  20. m_BaseMonsterAdon = monster;
  21. bulletDir = dir;
  22. skillIndex = _skillIndex;
  23. targetPos = _targetPos;
  24. distanceToTarget = Vector3.Distance(this.transform.position, targetPos);
  25. }
  26. void FixedUpdate()
  27. {
  28. this.transform.LookAt(targetPos);
  29. float angle = Mathf.Min(1, Vector3.Distance(this.transform.position, targetPos) / distanceToTarget) * 45;
  30. this.transform.rotation = this.transform.rotation * Quaternion.Euler(Mathf.Clamp(-angle, -45, 45), 0, 0);
  31. float currentDist = Vector3.Distance(this.transform.position, targetPos);
  32. if (currentDist < 0.5f)
  33. {
  34. // 爆炸特效
  35. GameObject effObj = Instantiate(m_BaseMonsterAdon.transform.Find("FBX/Effect_000/Bomb/Monster_Bomb1").gameObject, transform.position, Quaternion.identity);
  36. effObj.SetActive(true);
  37. Destroy(effObj, 2.0f);
  38. Destroy(gameObject);
  39. }
  40. this.transform.Translate(Vector3.forward * Mathf.Min(speed * Time.deltaTime, currentDist));
  41. }
  42. /// <summary>
  43. /// 武器技能触发事件
  44. /// </summary>
  45. /// <param name="collision"></param>
  46. void OnTriggerEnter(Collider collision)
  47. {
  48. if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))//玩家层
  49. {
  50. Debug.Log("碰撞敌人");
  51. // //Debug.Log("OnTriggerEnter:" + collision.gameObject.name);
  52. BaseHero component = collision.gameObject.GetComponent<BaseHero>();
  53. //发送战斗信息,等待后台处理逻辑返回数据
  54. BulletMessage.catSkillFun(m_BaseMonsterAdon.mData.UID, m_BaseMonsterAdon.mData.GetSKillNormal(skillIndex, 1),
  55. false, (int)X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, component.mData.UID, false);
  56. }
  57. }
  58. }
  59. }