Skip to content

Commit 849e29f

Browse files
Example3
1 parent 535d555 commit 849e29f

File tree

82 files changed

+13521
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+13521
-2
lines changed

Assets/Script/Example1/GetPoint.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
public class GetPoint : MonoBehaviour
7+
{
8+
// 坐标点A
9+
public Vector2 a;
10+
11+
// 坐标点B
12+
public Vector2 b;
13+
14+
// 比值
15+
public float ratio;
16+
17+
private void Update()
18+
{
19+
var position = Vector3.Lerp(a, b, ratio);
20+
transform.position = position;
21+
}
22+
}

Assets/Script/Example1/GetPoint.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Script/Example3/Lerp.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using UnityEngine;
3+
4+
public class Lerp : MonoBehaviour
5+
{
6+
// 终点
7+
public Vector3 b;
8+
// 开始位置
9+
public Vector3 a;
10+
// 持续时间
11+
public float duraction = 1f;
12+
// 记录运行时间
13+
private float _timeElapsed = 0;
14+
15+
private void Start()
16+
{
17+
transform.position = a;
18+
}
19+
20+
private void Update()
21+
{
22+
Vector3 valueToLerp;
23+
_timeElapsed += Time.deltaTime;
24+
if (_timeElapsed < duraction)
25+
{
26+
valueToLerp = Vector3.Lerp(a, b, _timeElapsed / duraction);
27+
}
28+
else
29+
{
30+
valueToLerp = b;
31+
}
32+
transform.position = valueToLerp;
33+
}
34+
}

Assets/Script/Example3/Lerp.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
6+
public class LerpMaterialColour : MonoBehaviour
7+
{
8+
9+
private Text text;
10+
public Color targetColor = new Color(0, 1, 0, 1);
11+
void Start()
12+
{
13+
text = gameObject.GetComponent<Text>();
14+
StartCoroutine(LerpFunctionWhile(targetColor, 5));
15+
}
16+
IEnumerator LerpFunction(Color endValue, float duration)
17+
{
18+
float time = 0;
19+
Color startValue = text.color;
20+
while (time < duration)
21+
{
22+
text.color = Color.Lerp(startValue, endValue, time / duration);
23+
time += Time.deltaTime;
24+
yield return null;
25+
}
26+
text.color = endValue;
27+
}
28+
29+
IEnumerator LerpFunctionWhile(Color endValue, float duration)
30+
{
31+
var start = text.color;
32+
var end = endValue;
33+
while (true)
34+
{
35+
float time = 0;
36+
Color startValue = text.color;
37+
var temp = text.color;
38+
while (time < duration)
39+
{
40+
text.color = Color.Lerp(startValue, endValue, time / duration);
41+
time += Time.deltaTime;
42+
yield return null;
43+
}
44+
text.color = endValue;
45+
46+
time = 0;
47+
startValue = text.color;
48+
while (time < duration)
49+
{
50+
text.color = Color.Lerp(startValue, temp, time / duration);
51+
time += Time.deltaTime;
52+
yield return null;
53+
}
54+
text.color = temp;
55+
}
56+
}
57+
}

Assets/Script/Example3/LerpMaterialColour.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class Lerp_Error1 : MonoBehaviour
6+
{
7+
// 终点
8+
public Vector3 targetPosition;
9+
// 开始位置
10+
public Vector3 startPosition;
11+
12+
private void Start()
13+
{
14+
transform.position = startPosition;
15+
}
16+
17+
void Update()
18+
{
19+
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime);
20+
}
21+
}

Assets/Script/Example3/Lerp_Error1.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/TextMesh Pro.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/TextMesh Pro/Documentation.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)