using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Debug class for controlling a character with keyboard input
|
|
/// </summary>
|
|
public class KeyboardInput : MonoBehaviour
|
|
{
|
|
|
|
#region Inspector Fields
|
|
[SerializeField]
|
|
[Tooltip("Character to move")]
|
|
private Character character;
|
|
|
|
public float characterSpeed;
|
|
#endregion Unity Functions
|
|
|
|
#region Unity Functions
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (character == null)
|
|
return;
|
|
|
|
if (Input.GetKeyDown(KeyCode.LeftArrow))
|
|
{
|
|
character.Rotate(Direction.Left);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.RightArrow))
|
|
{
|
|
character.Rotate(Direction.Right);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.UpArrow))
|
|
{
|
|
character.Move(Direction.Forward, characterSpeed);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
character.Jump(Direction.Forward);
|
|
}
|
|
}
|
|
|
|
//if character is empty check on object for it
|
|
private void OnValidate()
|
|
{
|
|
if (character == null)
|
|
character = GetComponent<Character>();
|
|
}
|
|
|
|
#endregion Unity Functions
|
|
}
|