12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class doorBehavior : MonoBehaviour
- {
- public bool close;
- public bool moving;
- public float speed;
- private const float closeCenter = 1.5f;
- private const float openCenter = 4.5f;
- // Start is called before the first frame update
- void Start()
- {
- close = true;
- speed = 1f;
- }
- void Move(float diff)
- {
- if (diff > speed * 0.04f)
- {
- transform.Translate(Vector3.down * speed * Time.deltaTime);
- }
- else if (diff < -speed * 0.04f)
- {
- transform.Translate(Vector3.up * speed * Time.deltaTime);
- }
- else
- {
- moving = false;
- return;
- }
- moving = true;
- }
- // Update is called once per frame
- void Update()
- {
- if (close)
- {
- float diff = transform.position.y - closeCenter;
- Move(diff);
- }
- else
- {
- float diff = transform.position.y - openCenter;
- Move(diff);
- }
- }
- }
|