Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ExampleClass : MonoBehaviour
- {
- public Transform target;
- public float maxHorizontalDistance = 10;
- void Update()
- {
- if(target == null) return;
- var distance = target.position - transform.position;
- distance.y = 0;
- var magnitude = distance.magnitude;
- if(magnitude > maxHorizontalDistance)
- {
- transform.position += distance.normalized * (magnitude - maxHorizontalDistance);
- }
- transform.LookAt(target);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement