- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ElevatorScript : MonoBehaviour
- {
- [SerializeField]
- private float height;
- [SerializeField]
- private float moveForce;
- private float timer = 1;
- [SerializeField]
- private bool isMoving = false;
- private bool ready = false;
- private ConditionCkecker cc;
- private Rigidbody rb;
- public Vector3 currentPos;
- public Vector3 startPos;
-
- public int whereAmI;
- void Start()
- {
- cc = GetComponent<ConditionCkecker>();
- rb = GetComponent<Rigidbody>();
- currentPos = transform.position;
- startPos = transform.position;
- }
-
- void Update()
- {
- if (timer > 0) timer -= Time.deltaTime;
- else { ready = cc.CheckConditions(); timer = 0.5f; }
- if (ready) isMoving = true;
-
-
- if(Vector3.Distance(transform.position, currentPos) >= height)
- {
- rb.velocity = Vector3.zero;
- isMoving = false;
- currentPos = transform.position;
- whereAmI = -whereAmI;
- }
- }
- private void FixedUpdate()
- {
- if (isMoving) transform.position = Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, transform.position.y + (height * whereAmI), transform.position.z), Time.deltaTime * 2);
-
- }
- private void OnCollisionStay(Collision collision)
- {
-
- }
- }