Newer
Older
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KineticFactBehaviour : MonoBehaviour
{
List<FunctionFact<float, float>> functions;
private int active_func_ind = -1;
private float time = 0;
private bool _done;
public bool done {
get => _done;
private set {
if (value && repeat) {
Reset();
StartExecution();
} else
_done = value;
}
}
public bool repeat = true;
public bool execute {
get { return active_func_ind < 0; }
set { if (value) StartExecution(); else StoppExecution(); }
}
private Transform startcondition;
void Awake()
{
startcondition = transform;
}
private void Update()
{
if (!execute)
return;
active_func_ind = functions.FindIndex(active_func_ind, ff => ff.domain.Item1 <= time);
if (!execute) {
done = true;
return;
}
transform.position = new Vector3(transform.position.x, functions[active_func_ind].function(time), transform.position.z);
time += Time.deltaTime;
}
public void Reset()
{
active_func_ind = -1;
time = 0;
transform.position = startcondition.position;
done = false;
}
public void StartExecution()
{
active_func_ind = 0;
}
public void StoppExecution()
{
active_func_ind = -1;
}
}