-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightController.cs
35 lines (35 loc) · 1.37 KB
/
LightController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightController : MonoBehaviour {
GameObject theCar;
Vector3 position;
float MaximumDistance = 5.1f;
float mult;
Vector3 Diff;
public static LightController instance;
// Use this for initialization
void Start () {
instance = this;
theCar = GameObject.FindWithTag ("Player");
transform.position = new Vector3 (theCar.transform.position.x, theCar.transform.position.y - 4f, -6f);
}
// Update is called once per frame
void Update () {
Diff = theCar.transform.position - new Vector3 (transform.position.x, transform.position.y, theCar.transform.position.z);
if (Diff.magnitude > MaximumDistance) {
mult = MaximumDistance / Diff.magnitude;
transform.position += Diff;
transform.position -= Diff * mult;
}
// transform.position = new Vector3 (theCar.transform.position.x, theCar.transform.position.y, )
}
public void UpdatePosition () {
Diff = theCar.transform.position - new Vector3 (transform.position.x, transform.position.y, theCar.transform.position.z);
if (Diff.magnitude > MaximumDistance) {
mult = MaximumDistance / Diff.magnitude;
transform.position += Diff;
transform.position -= Diff * mult;
}
}
}