Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Platforms : MonoBehaviour {
- public bool upDown;
- public bool leftRight;
- public float transDistance;
- public bool damaging;
- public bool disappearing;
- public float safeLength;
- public float warningLength;
- public float dangerLength;
- public float damageGiven;
- Vector3 startPos;
- Vector3 endPos;
- float progress = 1f;
- public float moveSpeed = 10f;
- public int stage = 0;
- float startTime = 0;
- float endtime;
- // Use this for initialization
- void Start () {
- startPos = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
- endtime = safeLength;
- }
- // Update is called once per frame
- void Update () {
- if (upDown || leftRight)
- {
- lerpMove();
- }
- if (damaging)
- {
- if (timer(safeLength) && stage == 0)
- {
- print("wark");
- damRun(1);
- }
- if (timer(warningLength) && stage == 1)
- {
- print("wink");
- damRun(2);
- }
- if (timer(dangerLength) && stage == 2)
- {
- print("wonk");
- damRun(3);
- }
- }
- if (disappearing)
- {
- disRun();
- }
- }
- bool timer(float countdown)
- {
- if (Time.time > endtime)
- {
- endtime = Time.time + countdown;
- return true;
- }
- return false;
- }
- void damRun(int callstage)
- {
- if (stage == 0)
- {
- renderer.material.color = Color.white;
- }
- else if (stage == 1)
- {
- renderer.material.color = Color.yellow;
- }
- else if (stage == 2)
- {
- renderer.material.color = Color.red;
- }
- stage = callstage;
- }
- void disRun()
- {
- }
- void lerpMove ()
- {
- if (upDown)
- {
- endPos = new Vector3(startPos.x, (startPos.y + transDistance), startPos.z);
- }
- else if (leftRight)
- {
- endPos = new Vector3((startPos.x + transDistance), startPos.y, startPos.z);
- }
- progress = (Time.time - startTime) / moveSpeed;
- transform.localPosition = Vector3.Lerp(startPos, endPos, progress);
- if (progress >= 1)
- {
- progress = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement