Guest User

Untitled

a guest
Aug 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class AutoDriveManager : Singleton<AutoDriveManager> {
  6.  
  7. public Engine engine;
  8. private Rigidbody2D engineRB;
  9. public Transform composition;
  10. public Transform aim;
  11. private float distance;
  12. bool autoDriveOn = true;
  13. bool upd = true;
  14. private int maxSpeed;
  15. private int direction;
  16. float koef;
  17.  
  18. public CompositionManager cm;
  19.  
  20. public float Distance
  21. {
  22. get
  23. {
  24. return composition.position.x - aim.position.x;
  25. }
  26.  
  27. set
  28. {
  29. distance = value;
  30. }
  31. }
  32.  
  33. public int MaxSpeed
  34. {
  35. get
  36. {
  37. return maxSpeed;
  38. }
  39.  
  40. set
  41. {
  42. maxSpeed = value;
  43. }
  44. }
  45.  
  46. public int Direction
  47. {
  48. get
  49. {
  50. if (Distance > 0)
  51. return -1;
  52. else
  53. return 1;
  54. }
  55.  
  56. set
  57. {
  58. direction = value;
  59. }
  60. }
  61.  
  62.  
  63.  
  64.  
  65. void Start () {
  66. engineRB = engine.GetComponent<Rigidbody2D>();
  67. MaxSpeed = 60;
  68. engine.ControllerPosition = 8 * Direction;
  69.  
  70.  
  71.  
  72. }
  73. void FixedUpdate () {
  74.  
  75. if (autoDriveOn)
  76. {
  77.  
  78. if ((int)(Time.deltaTime * engineRB.velocity.magnitude * 5) > MaxSpeed)
  79. {
  80. engine.engineControllerUseBrakes();
  81. Debug.Log("More " + (MaxSpeed - (int)(Time.deltaTime * engineRB.velocity.magnitude * 5)));
  82. }
  83. else
  84. {
  85. if (Mathf.Abs(Distance) > 3000)
  86. {
  87. engine.ControllerPosition = 8 * Direction;
  88. MaxSpeed = 40;
  89. }
  90. if (Mathf.Abs(Distance) < 3000 && Mathf.Abs(Distance) > 500)
  91. {
  92. MaxSpeed = 25;
  93. engine.ControllerPosition = 4 * Direction;
  94. }
  95. if (Mathf.Abs(Distance) < 700 && Mathf.Abs(Distance) > 30)
  96. {
  97. MaxSpeed = 10;
  98. engine.ControllerPosition = 1 * Direction;
  99. }
  100. if (Mathf.Abs(Distance) < 30)
  101. engine.engineControllerUseBrakes();
  102. }
  103. }
  104.  
  105.  
  106. }
  107.  
  108. }
Add Comment
Please, Sign In to add comment