This repository was archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNextIndicatorAnimation.cs
More file actions
100 lines (84 loc) · 2.84 KB
/
Copy pathNextIndicatorAnimation.cs
File metadata and controls
100 lines (84 loc) · 2.84 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NextIndicatorAnimation : MonoBehaviour
{
private Image _sR;
private bool _started = false;
private Vector2 initialPosition, finalPosition;
private float timeAnimationEnd;
private float animationStartTime;
private float timeOfAnimation;
private bool animating = true;
private bool directionDown;
private void Start()
{
directionDown = true;
_sR = GetComponent<Image>();
_started = true;
initialPosition = transform.position;
finalPosition = new Vector2(initialPosition.x,initialPosition.y-10);
}
// Update is called once per frame
void Update()
{
animationStartTime += Time.deltaTime;
if (directionDown)
{
transform.position = Vector3.Lerp(transform.position,finalPosition, animationStartTime/5f);
if (transform.position.y - finalPosition.y < .002f)
{
directionDown = false;
animationStartTime = 0;
}
}
else
{
animationStartTime += Time.deltaTime;
transform.position = Vector3.Lerp(transform.position, initialPosition, animationStartTime/5f);
if (initialPosition.y -transform.position.y < .002f)
{
directionDown = true;
animationStartTime = 0;
}
}
/*var curTime = Time.time;
if(animating)
{
timeOfAnimation += Time.deltaTime;
if (curTime - animationStartTime < .41f)
{
transform.position = Vector2.Lerp(transform.position, finalPosition, timeOfAnimation / 2.5f);
Debug.Log($"Position at {transform.position.y}. Time of animation is {timeOfAnimation}");
}
else if (curTime - animationStartTime <= .82f)
{
transform.position = Vector2.Lerp(transform.position, initialPosition, (timeOfAnimation - .41f) / 2.5f);
}
else
{
/*animating = false;
timeAnimationEnd = curTime;#1#
animationStartTime = curTime;
timeOfAnimation = 0f;
}
return;
}
if (!animating && curTime - timeAnimationEnd > .75f)
{
animating = true;
animationStartTime = curTime;
timeOfAnimation = 0f;
return;
}*/
}
//since we set things inactive and whatnot in our scripts, it may happen in the middle of an animation
private void OnEnable()
{
if (_started)
{
transform.position = initialPosition;
}
}
}