1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/CameraControl.cs

32 lines
826 B
C#
Raw Normal View History

2018-04-21 20:19:06 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour {
[SerializeField]
private GameObject followThis;
2018-04-21 20:19:06 +02:00
private Vector3 offset;
2018-04-21 20:19:06 +02:00
void Start() {
if ( followThis == null )
return;
offset = transform.position - followThis.transform.position;
}
2018-04-21 20:19:06 +02:00
void LateUpdate() {
if ( followThis == null )
return;
2018-04-22 23:50:55 +02:00
var target = followThis.transform.position; // + offset;
var targetVec = target - transform.position;
targetVec.Scale(new Vector3(0.05f, 0.05f, 0));
2018-04-21 20:19:06 +02:00
transform.position = transform.position + targetVec;
}
public void SetFollow(GameObject g) {
followThis = g;
offset = transform.position - followThis.transform.position;
}
2018-04-21 20:19:06 +02:00
}