This repository has been archived on 2026-04-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
UnityLearn-2D/UnityBuch-Projekt1/Assets/Scripts/PlayerControl.cs
T
2026-03-11 20:53:56 +01:00

36 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerControl : MonoBehaviour
{
private CharacterController Figur;
public float Speed = 5.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
Figur = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
// old Input handling - used in book
/*
if (Input.GetKey(KeyCode.LeftArrow))
Figur.Move(Vector3.left * Time.deltaTime * Speed);
if (Input.GetKey(KeyCode.RightArrow))
Figur.Move(Vector3.right * Time.deltaTime * Speed);
*/
//new Input handling - arrows and wasd
if (Keyboard.current.leftArrowKey.isPressed || Keyboard.current.aKey.isPressed)
Figur.Move(Vector3.left * Time.deltaTime * Speed);
if (Keyboard.current.rightArrowKey.isPressed || Keyboard.current.dKey.isPressed)
Figur.Move(Vector3.right * Time.deltaTime * Speed);
if (Keyboard.current.upArrowKey.isPressed || Keyboard.current.wKey.isPressed)
Figur.Move(Vector3.up * Time.deltaTime * Speed);
if (Keyboard.current.downArrowKey.isPressed || Keyboard.current.sKey.isPressed)
Figur.Move(Vector3.down * Time.deltaTime * Speed);
}
}