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 MovingSpikeShowedNew : MonoBehaviour
- {
- public bool showed;
- public bool hided;
- public bool showing;
- public bool hiding;
- private Vector3 showedPosition;
- private Vector3 hidedPosition;
- public float moveTime; // 0.005
- public float waitTime; // 0.5
- private float openSize;
- private GameObject player;
- // Start is called before the first frame update
- void Start()
- {
- player = GameObject.Find("Player New");
- showedPosition = transform.localPosition;
- openSize = 0.08f;
- }
- // Update is called once per frame
- void Update()
- {
- if (transform.localPosition == showedPosition)
- {
- showed = true;
- hided = false;
- showing = false;
- }
- if (transform.localPosition == showedPosition - new Vector3(0, openSize, 0))
- {
- showed = false;
- hided = true;
- hiding = false;
- }
- if (hiding)
- {
- if (player.GetComponent<PlayerNew>().levelrotating == false)
- {
- transform.Translate(Vector3.down * moveTime);
- showing = false;
- showed = false;
- hided = false;
- }
- }
- if (showing)
- {
- if (player.GetComponent<PlayerNew>().levelrotating == false)
- {
- transform.Translate(Vector3.up * moveTime);
- hiding = false;
- showed = false;
- hided = false;
- }
- }
- if (showed)
- {
- StartCoroutine(hide());
- }
- if (hided)
- {
- StartCoroutine(show());
- }
- }
- IEnumerator show()
- {
- yield return new WaitForSecondsRealtime(waitTime);
- showing = true;
- }
- IEnumerator hide()
- {
- yield return new WaitForSecondsRealtime(waitTime);
- hiding = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement