Advertisement
crystalguy123

Untitled

Feb 7th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Moving_Object : MonoBehaviour
  6. {
  7. public GameObject objectToMove;
  8. public Transform start;
  9. public Transform end;
  10. public float moveSpeed;
  11.  
  12. private Vector3 currentTarget;
  13.  
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. currentTarget = end.position;
  18. }
  19.  
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. objectToMove.transform.position = Vector3.MoveTowards(objectToMove.transform.position, currentTarget, moveSpeed * Time.deltaTime);
  24.  
  25. if(objectToMove.transform.position == end.position)
  26. {
  27. currentTarget = start.position;
  28. }
  29. if(objectToMove.transform.position == start.position)
  30. {
  31. currentTarget = end.position;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement