forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatMover.cs
More file actions
79 lines (56 loc) · 2.12 KB
/
Copy pathCatMover.cs
File metadata and controls
79 lines (56 loc) · 2.12 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
using System.Collections;
using UnityEngine;
namespace ModuleManager.Cats
{
public class CatMover : MonoBehaviour
{
public Vector3 spos;
public float vel = 5;
private float offsetY;
public TrailRenderer trail;
private SpriteRenderer spriteRenderer;
private int totalLenth = 100;
private float activePos = 0;
public float scale = 2;
private const float time = 5;
private const float trailTime = time / 4;
private bool clearTrail = false;
// Use this for initialization
void Start()
{
trail = this.GetComponent<TrailRenderer>();
trail.sortingOrder = 2;
spriteRenderer = this.GetComponent<SpriteRenderer>();
offsetY = Mathf.FloorToInt(0.2f * Screen.height);
spos.z = -1;
totalLenth = (int) (Screen.width / time * trail.time) + 150;
trail.time = trailTime;
trail.widthCurve = new AnimationCurve(new Keyframe(0, trail.startWidth ), new Keyframe(0.7f, trail.startWidth), new Keyframe(1, trail.startWidth * 0.9f));
clearTrail = true;
}
void Update()
{
if (trail.time <= 0f)
{
trail.time = trailTime;
}
activePos += ((Screen.width / time) * Time.deltaTime);
if (activePos > (Screen.width + totalLenth))
{
activePos = -spriteRenderer.sprite.rect.width;
clearTrail = true;
}
float f = 2f * Mathf.PI * (activePos) / (Screen.width * 0.5f);
float heightOffset = Mathf.Sin(f) * (spriteRenderer.sprite.rect.height * scale);
spos.x = activePos;
spos.y = offsetY + heightOffset;
transform.position = KSP.UI.UIMainCamera.Camera.ScreenToWorldPoint(spos);
transform.rotation = Quaternion.Euler(0, 0, Mathf.Cos(f) * 0.25f * Mathf.PI * Mathf.Rad2Deg);
if (clearTrail)
{
trail.Clear();
clearTrail = false;
}
}
}
}