Advertisement
talmud

Follow Target

Oct 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. /// <summary>
  6. /// GameObject will follow target transform constantly.
  7. /// </summary>
  8. public class FollowTarget : MonoBehaviour {
  9.  
  10. /// <summary>
  11. /// The target we are following.
  12. /// </summary>
  13. public Transform target;
  14.  
  15. /// <summary>
  16. /// How fast we move towards target.
  17. /// </summary>
  18. public float speed;
  19.  
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23. // set our position closer to target
  24. transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
  25.  
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement