created unity project, chapter 1 and 2 done

This commit is contained in:
BeatriceAl
2026-03-10 23:20:34 +01:00
parent 1836f5084a
commit b67aee52c6
30 changed files with 4401 additions and 0 deletions
@@ -0,0 +1,49 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class SphereControl : MonoBehaviour
{
Rigidbody body;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
body = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// old Input handling - used in book
/*
if (Input.GetKey(KeyCode.LeftArrow))
body.AddForce(Vector3.left * 5);
if (Input.GetKey(KeyCode.RightArrow))
body.AddForce(Vector3.right * 5);
if (Input.GetKey(KeyCode.UpArrow))
body.AddForce(Vector3.up * 5);
if (Input.GetKey(KeyCode.DownArrow))
body.AddForce(Vector3.down * 5);
*/
//new Input handling - arrows and wasd
if (Keyboard.current.leftArrowKey.isPressed || Keyboard.current.aKey.isPressed){
//body.AddForce(Vector3.left * 5);
body.MovePosition(body.position + Vector3.left * Time.deltaTime * 5);
}
if (Keyboard.current.rightArrowKey.isPressed || Keyboard.current.dKey.isPressed){
//body.AddForce(Vector3.right * 5);
body.MovePosition(body.position + Vector3.right * Time.deltaTime * 5);
}
if (Keyboard.current.upArrowKey.isPressed || Keyboard.current.wKey.isPressed){
//body.AddForce(Vector3.up * 5);
body.MovePosition(body.position + Vector3.up * Time.deltaTime * 10);
}
/*
if (Keyboard.current.downArrowKey.isPressed || Keyboard.current.sKey.isPressed){
body.MovePosition(body.position + Vector3.down * Time.deltaTime * 5);
}
*/
}
}