Dart_Motion.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Dart_Motion : MonoBehaviour
  5. {
  6. public float speed;
  7. public float timeLim;
  8. //Quaternion rota;
  9. public GameObject bult;
  10. //private int interval;
  11. private float time;
  12. //private int tag = 1;
  13. public enum type
  14. {
  15. normal = 0,
  16. half,
  17. left_half,
  18. right_half,
  19. special,
  20. };
  21. public type style = type.normal;
  22. private float sp_ro = 0;
  23. // Use this for initialization
  24. public GameObject ef;
  25. public float deadTime;
  26. void Start()
  27. {
  28. time = timeLim-0.1f;
  29. Vector3 mov = transform.rotation * Vector3.forward;
  30. GetComponent<Rigidbody>().AddForce(mov * speed * 10);
  31. }
  32. // Update is called once per frame
  33. void Update()
  34. {
  35. speed -= Time.deltaTime * 10;
  36. if (speed <= 0)
  37. {
  38. GetComponent<Rigidbody>().velocity = Vector3.zero;
  39. Boom();
  40. time += Time.deltaTime;
  41. deadTime -= Time.deltaTime;
  42. }
  43. if (deadTime <= 0) {
  44. Instantiate(ef, transform.position, Quaternion.identity);
  45. Destroy(this.gameObject);
  46. }
  47. if (style == type.special && time >= timeLim)
  48. {
  49. Quaternion rotation = new Quaternion();
  50. sp_ro += 4;
  51. rotation.eulerAngles = new Vector3(0, sp_ro * 0.2f, 0);
  52. Instantiate(bult, transform.position , rotation);
  53. time = 0;
  54. }
  55. }
  56. void Boom()
  57. {
  58. List<float> rotalist = new List<float>();
  59. switch ((int)style)
  60. {
  61. case (int)type.normal:
  62. for (int i = 0; i <= 25; i++)
  63. {
  64. rotalist.Add(i * 0.25f);
  65. }
  66. break;
  67. case (int)type.half:
  68. for (int i = 0; i <= 15; i++)//30
  69. {
  70. rotalist.Add(i * 0.2f);//0.4
  71. }
  72. break;
  73. case (int)type.left_half:
  74. for (int i = 8; i <= 23; i++)//30
  75. {
  76. rotalist.Add(i * 0.2f);//0.4
  77. }
  78. break;
  79. case (int)type.right_half:
  80. for (int i = 15; i <= 30; i++)//30
  81. {
  82. rotalist.Add(i * 0.2f);//0.4
  83. }
  84. break;
  85. default:
  86. break;
  87. }
  88. if (rotalist.Count > 0)
  89. {
  90. Quaternion rota = new Quaternion();
  91. rotalist.ForEach(r =>
  92. {
  93. rota.eulerAngles = new Vector3(0, r, 0);
  94. Instantiate(bult, transform.position + new Vector3(Mathf.Sin(r), 0, Mathf.Cos(r)), rota);
  95. });
  96. Instantiate(ef, transform.position, Quaternion.identity);
  97. Destroy(this.gameObject);
  98. }
  99. }
  100. }