Initial commit: Unity project setup
This commit is contained in:
52
Assets/Scripts/BallController.cs
Normal file
52
Assets/Scripts/BallController.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class BallController : MonoBehaviour {
|
||||
private float ballSpeed;
|
||||
private float brakeForce;
|
||||
private float jumpForce;
|
||||
private Rigidbody rb;
|
||||
float outOfBounds = -1.8f;
|
||||
|
||||
public void Start() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
ballSpeed = 3f;
|
||||
brakeForce = 0.3f;
|
||||
jumpForce = 14f;
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
KeyHandler();
|
||||
CheckPlayerOut();
|
||||
}
|
||||
|
||||
void CheckPlayerOut() {
|
||||
if (transform.position.y < outOfBounds) {
|
||||
transform.position = new Vector3(0, 1f, 0);
|
||||
transform.rotation = Quaternion.Euler(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void KeyHandler() {
|
||||
if (Keyboard.current.wKey.isPressed) {
|
||||
rb.AddForce(Vector3.forward * ballSpeed);
|
||||
}
|
||||
else if (Keyboard.current.sKey.isPressed) {
|
||||
rb.AddForce(Vector3.back * ballSpeed);
|
||||
}
|
||||
else if (Keyboard.current.dKey.isPressed) {
|
||||
rb.AddForce(Vector3.right * ballSpeed);
|
||||
}
|
||||
else if (Keyboard.current.aKey.isPressed) {
|
||||
rb.AddForce(Vector3.left * ballSpeed);
|
||||
}
|
||||
if (Keyboard.current.spaceKey.isPressed && transform.position.y < 1) {
|
||||
Debug.Log("KrossKross will make you...");
|
||||
rb.AddForce(Vector3.up * jumpForce);
|
||||
}
|
||||
else {
|
||||
rb.AddForce(-rb.linearVelocity * brakeForce);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/BallController.cs.meta
Normal file
2
Assets/Scripts/BallController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 561b0ece2be724c30967b132975bd626
|
||||
14
Assets/Scripts/CameraFollow.cs
Normal file
14
Assets/Scripts/CameraFollow.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour {
|
||||
public GameObject player;
|
||||
private Vector3 offset;
|
||||
|
||||
void Start() {
|
||||
offset = transform.position;
|
||||
}
|
||||
|
||||
void LateUpdate() {
|
||||
transform.position = player.transform.position + offset;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/CameraFollow.cs.meta
Normal file
2
Assets/Scripts/CameraFollow.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58a815f668cf14fe283b97e6adcb2eb4
|
||||
Reference in New Issue
Block a user