forked from molleindustria/distributedAuthorityClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraFollow.cs
34 lines (28 loc) · 892 Bytes
/
CameraFollow.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
// Smooth towards the current object
public float smoothTime = 0.3F;
private Vector3 velocity = Vector3.zero;
public Vector3 offset = new Vector3(0,10,-10);
private void Start()
{
//if it's my avatar make the camera follow me
if (gameObject.name == Net.myId)
{
}
else
{
this.enabled = false;
}
}
void Update()
{
// Define a target position above and behind the target transform
Vector3 targetPosition = transform.position + offset;
// Smoothly move the camera towards that target position
Camera.main.transform.position = Vector3.SmoothDamp(Camera.main.transform.position, targetPosition, ref velocity, smoothTime);
}
}