| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class FollowBehaviour : MonoBehaviour |
| | 6 | | { |
| | 7 | | public GameObject target; |
| | 8 | | public bool followRot; |
| | 9 | | public bool followPos; |
| | 10 | | public bool ignoreYAxis = false; |
| | 11 | |
|
| | 12 | | private void LateUpdate() |
| | 13 | | { |
| 0 | 14 | | if (target == null) |
| 0 | 15 | | return; |
| | 16 | |
|
| 0 | 17 | | if (followRot) |
| 0 | 18 | | this.transform.rotation = target.transform.rotation; |
| | 19 | |
|
| 0 | 20 | | if (followPos) |
| | 21 | | { |
| 0 | 22 | | Vector3 pos = target.transform.position; |
| 0 | 23 | | if (ignoreYAxis) |
| | 24 | | { |
| 0 | 25 | | pos.y = 0; |
| | 26 | | } |
| 0 | 27 | | this.transform.position = pos; |
| | 28 | | } |
| 0 | 29 | | } |
| | 30 | | } |