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 PlatformScript : MonoBehaviour {
- public GameObject arrow;
- public bool isHorizontal = true;
- public float speed = 2f;
- public float min;
- public float max;
- bool directionPlus = true;
- void Start() {
- SetDirection(true);
- }
- void SetDirection(bool dir) {
- directionPlus = dir;
- float angle = isHorizontal ? (dir ? 0 : 180) : (dir ? 90 : 270);
- arrow.transform.eulerAngles = new Vector3(arrow.transform.eulerAngles.x, arrow.transform.eulerAngles.y, angle);
- }
- void FixedUpdate() {
- if (isHorizontal) {
- if (transform.position.x > max) {
- SetDirection(false);
- } else if (transform.position.x < min) {
- SetDirection(true);
- }
- } else {
- if (transform.position.y > max) {
- SetDirection(false);
- } else if (transform.position.y < min) {
- SetDirection(true);
- }
- }
- float delta = speed * (directionPlus ? 1 : -1) * Time.deltaTime;
- if (isHorizontal) {
- transform.position = new Vector3(transform.position.x + delta, transform.position.y, transform.position.z);
- } else {
- transform.position = new Vector3(transform.position.x, transform.position.y + delta, transform.position.z);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement