campfire/Assets/Scripts/TutorialController.cs

31 lines
803 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CanvasGroup))]
public class TutorialController : MonoBehaviour {
public KeyCode ToggleKey;
public bool Toggled = true;
public float AnimationLerpFactor = 10f;
private RectTransform Rect;
private void Awake() {
Rect = GetComponent<RectTransform>();
}
private void Start() {
Rect.anchoredPosition = new Vector2(-100, -100);
}
private void Update() {
if (Input.GetKeyDown(ToggleKey)) {
Toggled = !Toggled;
}
Vector2 Pos = Rect.anchoredPosition;
Pos.y = Mathf.Lerp(Pos.y, Toggled ? -100 : (Rect.rect.height + 10), AnimationLerpFactor * Time.deltaTime);
Rect.anchoredPosition = Pos;
}
}