TrapManager.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using UnityEngine;
  3. public class TrapManager : MonoBehaviour
  4. {
  5. private Transform player
  6. {
  7. get
  8. {
  9. return R.Player.Transform;
  10. }
  11. }
  12. private void Start()
  13. {
  14. if (this.distance == 0f)
  15. {
  16. this.startLunch = true;
  17. }
  18. }
  19. private void Update()
  20. {
  21. this.Lunch();
  22. if (this.startLunch)
  23. {
  24. return;
  25. }
  26. if (Mathf.Abs(this.player.position.x - (base.transform.position.x + this.distance)) <= 1f)
  27. {
  28. this.startLunch = true;
  29. }
  30. }
  31. private void Lunch()
  32. {
  33. if (!this.startLunch)
  34. {
  35. return;
  36. }
  37. this.currentTime -= Time.deltaTime;
  38. if (this.currentTime <= 0f)
  39. {
  40. this.currentTime = this.lunchInterval;
  41. Transform transform = UnityEngine.Object.Instantiate<Transform>(this.prefab, base.transform.position + (Vector3)this.lunchOffset, Quaternion.identity);
  42. transform.rotation = Quaternion.Euler(this.euler);
  43. transform.GetComponent<Rigidbody2D>().velocity = this.speed;
  44. if (transform.GetComponent<TrapAttack>() != null)
  45. {
  46. transform.GetComponent<TrapInfoSetting>().SetInfo(this.atkType, this.damage, (float)this.atkInterval);
  47. }
  48. }
  49. }
  50. [Header("发射间隔")]
  51. public float lunchInterval;
  52. public Transform prefab;
  53. [Header("发射速度")]
  54. public Vector2 speed;
  55. public Vector3 euler;
  56. [Header("发射点")]
  57. public Vector2 lunchOffset;
  58. private float currentTime;
  59. [Header("导弹伤害")]
  60. public int damage;
  61. [Header("导弹伤害间隔")]
  62. public int atkInterval;
  63. [Header("导弹攻击类型")]
  64. public TrapAttack.AttackType atkType;
  65. [Header("触发距离")]
  66. public float distance;
  67. private bool startLunch;
  68. }