fr0stn1k

Unity3(FromPointToPoint)_Kovylov

Mar 7th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ToPointAndBack : MonoBehaviour
  4. {
  5. private Transform Self;
  6. public Vector3 StartVector3;
  7. public Vector3 TargetVector3;
  8. private Vector3 MovingVector3;
  9. public float Speed;
  10.  
  11. void Start()
  12. {
  13. Self = GetComponent<Transform>();
  14. StartVector3 = Self.position;
  15. MovingVector3 = TargetVector3;
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update ()
  20. {
  21. MoveFromAtoB();
  22. }
  23.  
  24.  
  25. private void MoveFromAtoB()
  26. {
  27. Self.Translate((MovingVector3 - Self.position).normalized * Speed * Time.deltaTime);
  28. //Проверка на преодоление координат точки Б объектом и присвоение координат точки А вектору движения
  29. if (Self.position.x > TargetVector3.x || Self.position.y > TargetVector3.y || Self.position.z > TargetVector3.z)
  30. MovingVector3 = StartVector3;
  31. //Проверка на преодоление координат точки А объектом и присвоение координат точки Б вектору движения
  32. if (Self.position.x < StartVector3.x || Self.position.y < StartVector3.y || Self.position.z < StartVector3.z)
  33. MovingVector3 = TargetVector3;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment