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);
        }
        */
    }

}
