You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LittleManComputer/LMC/Assets/DoorOpen.cs

61 lines
1.6 KiB
C#

1 year ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorAnimation : MonoBehaviour
{
// Start is called before the first frame update
1 year ago
[SerializeField]
1 year ago
public int CurrentAction = 0;
public int TimeRotation = 0;
public float AngleRotation = -160.0f, TimePassed = 0.0f;
1 year ago
public bool DoorIsMoving = false;
void Start()
{
1 year ago
}
public void OpenDoor() {
CurrentAction = 1;
}
public void CloseDoor() {
CurrentAction = 2;
}
// Update is called once per frame
void Update()
{
if(CurrentAction == 1) {
if(TimePassed < 1.0f) {
float NewTime = Mathf.Min(1.0f - TimePassed, Time.deltaTime);
float AngleRotate = AngleRotation * NewTime;
transform.Rotate(0, 0, AngleRotate);
TimePassed += NewTime;
1 year ago
DoorIsMoving = true;
}
else {
DoorIsMoving = false;
CurrentAction = 0;
TimePassed = 0.0f;
1 year ago
}
}
else if(CurrentAction == 2) {
if(TimePassed < 1.0f) {
float NewTime = Mathf.Min(1.0f - TimePassed, Time.deltaTime);
float AngleRotate = -AngleRotation * NewTime;
transform.Rotate(0, 0, AngleRotate);
TimePassed += NewTime;
1 year ago
DoorIsMoving = true;
}
else {
DoorIsMoving = false;
CurrentAction = 0;
TimePassed = 0.0f;
1 year ago
}
}
}
}