Bullet2201001.cs 2.0 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. /// 2201001子弹
  9. /// </summary>
  10. public class Bullet2201001 : MonoBehaviour
  11. {
  12. /// <summary>
  13. /// 子弹步进速度
  14. /// </summary>
  15. public float velocity = 20f;
  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. public void SetMonster(BaseMonsterAdon monster, Vector3 dir)
  24. {
  25. m_BaseMonsterAdon = monster;
  26. bulletDir = dir;
  27. }
  28. void FixedUpdate()
  29. {
  30. Vector3 step = bulletDir * Time.deltaTime * velocity;//子弹步进
  31. timer += Time.deltaTime;
  32. // 生命周期到了则销毁
  33. if (timer >= lifeTime)
  34. {
  35. Destroy(gameObject);
  36. }
  37. transform.position += step;//向前步进
  38. }
  39. /// <summary>
  40. /// 武器技能触发事件
  41. /// </summary>
  42. /// <param name="collision"></param>
  43. void OnTriggerEnter(Collider collision)
  44. {
  45. if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))//玩家层
  46. {
  47. Debug.Log("碰撞敌人");
  48. // //Debug.Log("OnTriggerEnter:" + collision.gameObject.name);
  49. BaseHero component = collision.gameObject.GetComponent<BaseHero>();
  50. //发送战斗信息,等待后台处理逻辑返回数据
  51. BulletMessage.catSkillFun(m_BaseMonsterAdon.mData.UID, m_BaseMonsterAdon.mData.GetSKillNormal(2, 1),
  52. false, (int)X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, component.mData.UID, false);
  53. Destroy(gameObject);
  54. }
  55. }
  56. }
  57. }