Added: unity project for SOLID

This commit is contained in:
2026-09-30 18:38:16 +02:00
parent c528093fdb
commit 285aa10221
89 changed files with 8440 additions and 0 deletions
@@ -0,0 +1,100 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
namespace NonSolid
{
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
[Header("Movement")]
[SerializeField] private float speed = 5f;
[SerializeField] private float rotationSpeed = 60f;
[Header("Firing")]
[SerializeField] private Transform shootSpawn;
[SerializeField] private Rigidbody projectilePrefab;
[SerializeField] private float shootForce = 10.0f;
[SerializeField] private FireType fireType;
[Header("Inputs")]
[SerializeField] private InputActionReference movementInputReference;
[SerializeField] private InputActionReference rotationInputReference;
[SerializeField] private InputActionReference fireInputReference;
private CharacterController _characterController;
private Vector2 _movementInput;
private Vector2 _rotationInput;
private void Awake()
{
_characterController = GetComponent<CharacterController>();
}
private void OnEnable()
{
movementInputReference.action.Enable();
rotationInputReference.action.Enable();
fireInputReference.action.Enable();
fireInputReference.action.performed += OnFireActionPerformed;
}
private void OnDisable()
{
movementInputReference.action.Disable();
rotationInputReference.action.Disable();
fireInputReference.action.Disable();
fireInputReference.action.performed -= OnFireActionPerformed;
}
private void FixedUpdate()
{
HandleInput();
MoveAndRotate();
}
private void HandleInput()
{
_movementInput = movementInputReference.action.ReadValue<Vector2>();
_rotationInput = rotationInputReference.action.ReadValue<Vector2>();
}
private void MoveAndRotate()
{
transform.Rotate(0, _rotationInput.x * Time.deltaTime * rotationSpeed, 0);
_characterController.Move(new Vector3(_movementInput.x, 0, _movementInput.y) * (speed * Time.deltaTime));
}
private void OnFireActionPerformed(InputAction.CallbackContext context)
{
Fire();
}
private void Fire()
{
switch (fireType)
{
case FireType.Bullet:
Rigidbody projectile = Instantiate(projectilePrefab, shootSpawn.position, shootSpawn.rotation);
projectile.AddForce(shootSpawn.forward * shootForce, ForceMode.Impulse);
break;
case FireType.Spell:
break;
case FireType.Laser:
break;
case FireType.Grenade:
break;
case FireType.Rocket:
break;
case FireType.Arrow:
break;
case FireType.Fireball:
break;
case FireType.Plasma:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}