Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlatformMovement : MonoBehaviour
- {
- public bool isVertical = true;
- public float start;
- public float end;
- public float speed = 4;
- public float waitingLenght = .5f;
- private float waitingTime = 0f;
- private bool isWaiting = false;
- private bool movingToEnd=true;
- // Update is called once per frame
- void Start()
- {
- }
- void Update()
- {
- if (isVertical)
- {
- if (movingToEnd && !isWaiting)
- {
- transform.Translate(Vector2.right * speed * Time.deltaTime);
- }
- if (!movingToEnd && !isWaiting)
- {
- transform.Translate(Vector2.left * speed * Time.deltaTime);
- }
- if (transform.position.x >= end && movingToEnd == true)
- {
- movingToEnd = false;
- isWaiting = true;
- waitingTime = waitingLenght;
- }
- if (transform.position.x <= start && movingToEnd == false)
- {
- movingToEnd = true;
- isWaiting = true;
- waitingTime = waitingLenght;
- }
- }
- else
- {
- if (movingToEnd && !isWaiting)
- {
- transform.Translate(Vector2.up * speed * Time.deltaTime);
- }
- if (!movingToEnd && !isWaiting)
- {
- transform.Translate(Vector2.down * speed * Time.deltaTime);
- }
- if (transform.position.y >= end && movingToEnd == true)
- {
- movingToEnd = false;
- isWaiting = true;
- waitingTime = waitingLenght;
- }
- if (transform.position.y <= start && movingToEnd == false)
- {
- movingToEnd = true;
- isWaiting = true;
- waitingTime = waitingLenght;
- }
- }
- if (isWaiting)
- {
- waitingTime -= Time.deltaTime;
- if (waitingTime <= 0)
- isWaiting = false;
- }
- }
- void Wait(float seconds)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement