Bullet2701001.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Adon.Game.BO;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace AdonGameKit
  6. {
  7. /// <summary>
  8. /// 2701001子弹
  9. /// </summary>
  10. public class Bullet2701001 : MonoBehaviour
  11. {
  12. /// <summary>
  13. /// 子弹步进速度
  14. /// </summary>
  15. public float velocity = 10f;
  16. /// <summary>
  17. /// 生命周期
  18. /// </summary>
  19. public float lifeTime = 5f;
  20. float timer = 0f; // 子弹生命周期计时
  21. public BaseMonsterAdon m_BaseMonsterAdon;
  22. private Vector3 bulletDir = Vector3.zero;
  23. private int skillIndex = 0;
  24. public void SetMonster(BaseMonsterAdon monster, Vector3 dir, int _skillIndex)
  25. {
  26. m_BaseMonsterAdon = monster;
  27. bulletDir = dir;
  28. skillIndex = _skillIndex;
  29. }
  30. void FixedUpdate()
  31. {
  32. Vector3 step = bulletDir * Time.deltaTime * velocity;//子弹步进
  33. timer += Time.deltaTime;
  34. // 生命周期到了则销毁
  35. if (timer >= lifeTime)
  36. {
  37. Destroy(gameObject);
  38. }
  39. transform.LookAt(transform.position + bulletDir * 1000);
  40. transform.position += step;//向前步进
  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("碰撞敌人" + collision.gameObject.name);
  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. Destroy(gameObject);
  57. }
  58. }
  59. }
  60. }