-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudscript.cs
More file actions
39 lines (35 loc) · 1.17 KB
/
cloudscript.cs
File metadata and controls
39 lines (35 loc) · 1.17 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
using UnityEngine;
public class cloudscript : MonoBehaviour
{
public float moveIntervalSeconds = 10f;
public float moveDistanceX = 5f;
private float timeSinceLastMove;
private float limit = 6f; //max allowed to move left (only moving left)
private float limitAmt = 0f;
private bool reverse = false;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
timeSinceLastMove = 0f;
}
// Update is called once per frame
void Update()
{
timeSinceLastMove += Time.deltaTime;
if (timeSinceLastMove >= moveIntervalSeconds)
{
if((limitAmt < limit)&&!reverse){
limitAmt+=moveDistanceX;
transform.position += new Vector3(moveDistanceX, 0f, 0f);
timeSinceLastMove = 0f;}
if (reverse && (limitAmt != limit)){ //go all the way back
limitAmt-=moveDistanceX;
transform.position += new Vector3(moveDistanceX, 0f, 0f);
timeSinceLastMove = 0f;
}
else{
reverse = true;
}
}
}
}