Chapter 3 done

This commit is contained in:
BeatriceAl
2026-03-11 20:53:56 +01:00
parent 53e2328522
commit cfd42a6db4
9 changed files with 680 additions and 0 deletions
@@ -0,0 +1,35 @@
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);
}
}