You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.2 KiB

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
}