add unity project
add SOLID examples
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DefaultNamespace.NonSolid
|
||||
{
|
||||
public class AreaOfEffect : MonoBehaviour
|
||||
{
|
||||
public enum AreaOfEffectType
|
||||
{
|
||||
Circle,
|
||||
Rectangle,
|
||||
Pentagon,
|
||||
Hexagon,
|
||||
}
|
||||
|
||||
[SerializeField] private AreaOfEffectType _areaOfEffectType;
|
||||
[SerializeField] private float _radius;
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
float area = 0.0f;
|
||||
|
||||
switch (_areaOfEffectType)
|
||||
{
|
||||
case AreaOfEffectType.Circle:
|
||||
area = Mathf.Pow(_radius, 2.0f) * Mathf.PI;
|
||||
break;
|
||||
case AreaOfEffectType.Rectangle:
|
||||
break;
|
||||
case AreaOfEffectType.Pentagon:
|
||||
break;
|
||||
case AreaOfEffectType.Hexagon:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b68af98e555247c78e25c77f6d3be08b
|
||||
timeCreated: 1742921835
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace DefaultNamespace.NonSolid
|
||||
{
|
||||
public enum FireType
|
||||
{
|
||||
Bullet,
|
||||
Spell,
|
||||
Arrow
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1fa0acb052c4955a864dd86e2e57aa7
|
||||
timeCreated: 1742920117
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30b03ab4d982417e8e22d58811009924
|
||||
timeCreated: 1742916420
|
||||
Reference in New Issue
Block a user