add unity project

add SOLID examples
This commit is contained in:
2025-04-09 07:49:12 +02:00
parent ff37858d12
commit a4f498a33d
102 changed files with 8244 additions and 0 deletions
@@ -0,0 +1,73 @@
using System;
using UnityEngine;
namespace DefaultNamespace.NonSolid
{
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
[SerializeField] private float _speed = 10.0f;
[SerializeField] private float _rotationSpeed = 60.0f;
[SerializeField] private Transform _shootSpawn;
[SerializeField] private Rigidbody _projectilePrefab;
[SerializeField] private float _shootForce = 10.0f;
[SerializeField] private FireType _fireType = FireType.Bullet;
private CharacterController _controller;
private Vector3 _movement = Vector3.zero;
private float _rotation = 0.0f;
private bool _isFiring = false;
private void Awake()
{
_controller = GetComponent<CharacterController>();
}
private void Update()
{
HandleInput();
Move();
Fire();
}
private void HandleInput()
{
_movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
_movement *= _speed * Time.deltaTime;
_rotation = Input.GetAxis("Mouse X") * _rotationSpeed * Time.deltaTime;
_isFiring = _isFiring || Input.GetButtonDown("Fire1");
}
private void Move()
{
_controller.Move(_movement);
_controller.transform.Rotate(Vector3.up, _rotation);
}
private void Fire()
{
if (!_isFiring) return;
_isFiring = false;
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.Arrow:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}