152 lines
4 KiB
C#
152 lines
4 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class Monarch : MonoBehaviour
|
|
{
|
|
Animator monarch;
|
|
public GameObject MainCamera;
|
|
|
|
InputMaster inputs;
|
|
//Vector2 move;
|
|
Vector2 rotate;
|
|
|
|
private void Awake()
|
|
{
|
|
inputs = new InputMaster();
|
|
|
|
inputs.Butterfly.Fly.performed += ctx => Fly();
|
|
inputs.Butterfly.Fly.canceled += ctx => Land();
|
|
|
|
inputs.Butterfly.Forward.performed += ctx => Forward();
|
|
inputs.Butterfly.Forward.canceled += ctx => Stop();
|
|
|
|
inputs.Butterfly.Rotation.performed += ctx => rotate = ctx.ReadValue<Vector2>();
|
|
inputs.Butterfly.Rotation.canceled += ctx => rotate = Vector2.zero;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
//inputs.PyPlayer.Enable();
|
|
inputs.Butterfly.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
//inputs.PyPlayer.Disable();
|
|
inputs.Butterfly.Disable();
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
monarch = GetComponent<Animator>();
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
Vector2 r = new Vector2(0, rotate.x) * 100f * Time.deltaTime;
|
|
transform.Rotate(r, Space.Self);
|
|
|
|
|
|
if ((monarch.GetCurrentAnimatorStateInfo(0).IsName("takeoff")) || (monarch.GetCurrentAnimatorStateInfo(0).IsName("landing")))
|
|
{
|
|
monarch.SetBool("takeoff", false);
|
|
monarch.SetBool("landing", false);
|
|
}
|
|
if ((Input.GetKeyUp(KeyCode.W)) || (Input.GetKeyUp(KeyCode.A)) || (Input.GetKeyUp(KeyCode.D)))
|
|
{
|
|
monarch.SetBool("idle2", true);
|
|
monarch.SetBool("walk", false);
|
|
monarch.SetBool("glide", true);
|
|
monarch.SetBool("turnleft", false);
|
|
monarch.SetBool("turnright", false);
|
|
monarch.SetBool("flyleft", false);
|
|
monarch.SetBool("flyright", false);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.W))
|
|
{
|
|
monarch.SetBool("walk", true);
|
|
monarch.SetBool("idle2", false);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.A))
|
|
{
|
|
monarch.SetBool("turnleft", true);
|
|
monarch.SetBool("flyleft", true);
|
|
monarch.SetBool("turnright", false);
|
|
monarch.SetBool("idle2", false);
|
|
monarch.SetBool("walk", false);
|
|
monarch.SetBool("glide", false);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.D))
|
|
{
|
|
monarch.SetBool("turnright", true);
|
|
monarch.SetBool("flyright", true);
|
|
monarch.SetBool("turnleft", false);
|
|
monarch.SetBool("idle", false);
|
|
monarch.SetBool("idle2", false);
|
|
monarch.SetBool("walk", false);
|
|
monarch.SetBool("glide", false);
|
|
}
|
|
if (Input.GetKey(KeyCode.Space))
|
|
{
|
|
monarch.SetBool("takeoff", true);
|
|
monarch.SetBool("landing", true);
|
|
monarch.SetBool("idle", false);
|
|
monarch.SetBool("glide", false);
|
|
}
|
|
|
|
|
|
// funktioniert nicht?
|
|
if (Input.GetKeyDown(KeyCode.Return))
|
|
{
|
|
monarch.SetBool("glide", false);
|
|
monarch.SetBool("flyinplace", true);
|
|
}
|
|
|
|
if (Input.GetKeyUp(KeyCode.Return))
|
|
{
|
|
monarch.SetBool("flyinplace", false);
|
|
monarch.SetBool("glide", true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.CompareTag("ShatterableGlass"))
|
|
{
|
|
print("!");
|
|
AudioSource source = other.gameObject.GetComponentInParent<AudioSource>();
|
|
source.Play();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void Fly()
|
|
{
|
|
monarch.SetBool("idle2", false);
|
|
monarch.SetBool("takeoff", true);
|
|
}
|
|
|
|
private void Land()
|
|
{
|
|
monarch.SetBool("glide", false);
|
|
monarch.SetBool("landing", true);
|
|
}
|
|
|
|
|
|
private void Forward()
|
|
{
|
|
monarch.SetBool("walk", true);
|
|
monarch.SetBool("idle2", false);
|
|
}
|
|
|
|
private void Stop()
|
|
{
|
|
monarch.SetBool("walk", false);
|
|
monarch.SetBool("idle2", true);
|
|
}
|
|
}
|