Bullet2501001_1.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Adon.Game.BO;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace AdonGameKit
  6. {
  7. /// <summary>
  8. /// 2501001 激光子弹
  9. /// </summary>
  10. public class Bullet2501001_1 : MonoBehaviour
  11. {
  12. /// <summary>
  13. /// 子弹步进速度
  14. /// </summary>
  15. public float velocity = 5;
  16. /// <summary>
  17. /// 生命周期
  18. /// </summary>
  19. public float lifeTime = 5f;
  20. public BaseMonsterAdon m_BaseMonsterAdon;
  21. private Vector3 bulletPos = Vector3.zero;
  22. private Transform bulletLine = null;
  23. private int skillIndex = 0;
  24. private bool run = false;
  25. private float bulletVal = 0;
  26. public void SetMonster(BaseMonsterAdon monster, Transform _bulletLine, Vector3 pos, int _skillIndex)
  27. {
  28. m_BaseMonsterAdon = monster;
  29. bulletLine = _bulletLine;
  30. bulletPos = pos;
  31. bulletPos.y = bulletLine.position.y;
  32. skillIndex = _skillIndex;
  33. run = true;
  34. bulletVal = 0;
  35. }
  36. void FixedUpdate()
  37. {
  38. if (run == false)
  39. {
  40. return;
  41. }
  42. bulletVal += Time.deltaTime * 4;
  43. if (bulletVal <= 1.0f)
  44. {
  45. transform.position = Vector3.Lerp(m_BaseMonsterAdon.transform.position, bulletPos, bulletVal);
  46. float dis = Vector3.Distance(m_BaseMonsterAdon.transform.position, transform.position);
  47. bulletLine.localScale = new Vector3(1, 1, dis);
  48. }
  49. else
  50. {
  51. Destroy(transform.parent.gameObject);
  52. }
  53. }
  54. /// <summary>
  55. /// 武器技能触发事件
  56. /// </summary>
  57. /// <param name="collision"></param>
  58. void OnTriggerEnter(Collider collision)
  59. {
  60. if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))//玩家层
  61. {
  62. Debug.Log("碰撞敌人");
  63. // //Debug.Log("OnTriggerEnter:" + collision.gameObject.name);
  64. BaseHero component = collision.gameObject.GetComponent<BaseHero>();
  65. //发送战斗信息,等待后台处理逻辑返回数据
  66. BulletMessage.catSkillFun(m_BaseMonsterAdon.mData.UID, m_BaseMonsterAdon.mData.GetSKillNormal(skillIndex, 1),
  67. false, (int)X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT, component.mData.UID, false);
  68. Destroy(transform.parent.gameObject);
  69. }
  70. }
  71. }
  72. }