TEB-2023-GD1/Assets/Scripts/SphereControl.cs

40 lines
916 B
C#
Raw Permalink Normal View History

2023-11-22 22:21:43 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SphereControl : MonoBehaviour
{
public Rigidbody rigidbody;
[Range(0.01f, 10.0f)]
public float speed = 1.0f;
[Range(0.01f, 1000.0f)]
public float jumpForce = 200.0f;
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.RightArrow))
{
rigidbody.AddForce(speed, 0, 0);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
rigidbody.AddForce(-speed, 0, 0);
}
if (Input.GetKey(KeyCode.UpArrow))
{
rigidbody.AddForce(0, 0, speed);
}
if (Input.GetKey(KeyCode.DownArrow))
{
rigidbody.AddForce(0, 0, -speed);
}
if (Input.GetKeyDown(KeyCode.Space))
{
rigidbody.AddForce(0, jumpForce, 0);
}
}
}