-
Notifications
You must be signed in to change notification settings - Fork 2
/
Follow.cs
36 lines (33 loc) · 1.1 KB
/
Follow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Follow : MonoBehaviour
{
public enum FollowOptions {MoveTowards, Lerp, SetPosition, SetParent }
[SerializeField] private FollowOptions _Option;
[SerializeField] private Transform _Target;
[SerializeField] private float _FollowSpeed;
private void Start()
{
if(_Option == FollowOptions.SetParent)
{
transform.parent = _Target.transform;
transform.localPosition = Vector3.zero;
}
}
void Update()
{
switch(_Option)
{
case FollowOptions.MoveTowards:
transform.position = Vector3.MoveTowards(transform.position, _Target.position, _FollowSpeed * Time.deltaTime);
break;
case FollowOptions.Lerp:
transform.position = Vector3.Lerp(transform.position, _Target.position, _FollowSpeed * Time.deltaTime);
break;
case FollowOptions.SetPosition:
transform.position = _Target.position;
break;
}
}
}