-
Notifications
You must be signed in to change notification settings - Fork 0
/
Follow.cs
32 lines (28 loc) · 874 Bytes
/
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Follow : MonoBehaviour
{
public GameObject target;
Vector3 offset;
bool offsetSet = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// save offset for first frame
if (!offsetSet){
offset = transform.position - target.transform.position;
offsetSet = true;
// log position and target position
// Debug.Log("position: " + transform.position);
// Debug.Log("target position: " + target.transform.position);
}
// follow target
transform.position = target.transform.position + offset;
// transform.position = target.transform.position;
}
}