+ Layer Boids, Boid로 분리 + Fish의 로직을 Boids(군집) 알고리즘으로 변경 + 군집에 이펙트를 통해 낚시 가시성 추가 + 테스트용 군집 애니메이션 추가 + Epic Toon EX 에셋의 스크립트 수정 버전 ㄴ ParticleWeapon(Layer 선택, UnityEvent Hit 델리게이트 기능 추가) 사용 + Cannon의 x축 회전 고정 + Cannon이 공격한 Layer에 따른 기능 변경 + DataManager에 PlayerInventory 추가 ㄴ 초창기에 사용한 코딩 삭제 + 초창기에 사용했던 스크립트들 일부 정리
82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class Cannon : MonoBehaviour
|
|
{
|
|
[Title("초기화 방식")]
|
|
[SerializeField] private bool autoInit = true;
|
|
|
|
[Title("캐논 변수")]
|
|
[SerializeField] private GameObject projectileObj;
|
|
[SerializeField] private Transform firePos;
|
|
[SerializeField] private float speed = 2000f;
|
|
[SerializeField] private float height = 50f;
|
|
[SerializeField] private Vector2 randomCatch = new(1, 4);
|
|
|
|
[Title("캐논 발사 카메라 효과")]
|
|
[SerializeField] private float cameraShakePower = 0.5f;
|
|
[SerializeField] private float cameraShakeDuration = 0.5f;
|
|
|
|
private float cannonRadius;
|
|
private LayerMask boidsLayer;
|
|
|
|
private void Awake()
|
|
{
|
|
if (autoInit)
|
|
{
|
|
Init();
|
|
}
|
|
}
|
|
|
|
[Button("셋팅 초기화")]
|
|
private void Init()
|
|
{
|
|
projectileObj = Utils.LoadFromFolder<GameObject>("Assets/05.Prefabs/Particles/GrenadeFire", "GrenadeFireOBJ", ".prefab");
|
|
firePos = transform.Find("FirePos");
|
|
cannonRadius = projectileObj.GetComponent<SphereCollider>()?.radius ??
|
|
projectileObj.GetComponent<ParticleWeapon>().colliderRadius;
|
|
boidsLayer = LayerMask.GetMask("Boids");
|
|
}
|
|
|
|
public void Fire(float chargingGauge)
|
|
{
|
|
VisualFeedbackManager.Inst.CameraShake(CameraManager.Inst.OceanCamera.BaseShipCam, cameraShakePower, cameraShakeDuration);
|
|
var projectile = Instantiate(projectileObj, firePos.position, Quaternion.identity);
|
|
var particleWeapon = projectile.GetComponent<ParticleWeapon>();
|
|
particleWeapon.onHitAction.AddListener(HandleCannonHit);
|
|
projectile.GetComponent<Rigidbody>().AddForce(transform.forward * (chargingGauge * speed));
|
|
}
|
|
|
|
private void HandleCannonHit(RaycastHit hit, float power)
|
|
{
|
|
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Water"))
|
|
{
|
|
var start = hit.point;
|
|
var direction = Vector3.down;
|
|
var radius = cannonRadius;
|
|
var maxDistance = height;
|
|
|
|
if (Physics.SphereCast(start, radius, direction, out var hitInfo, maxDistance,
|
|
boidsLayer, QueryTriggerInteraction.Collide))
|
|
{
|
|
Debug.DrawRay(start, direction * height, Color.green, 3f);
|
|
|
|
var hitBoids = hitInfo.collider.GetComponentInParent<Boids>();
|
|
hitBoids.CatchBoid(Random.Range((int)randomCatch.x, (int)randomCatch.y));
|
|
}
|
|
else
|
|
{
|
|
Debug.DrawRay(start, direction * height, Color.red, 3f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
hit.transform.GetComponent<IDamageable>()?.TakeDamage(power);
|
|
}
|
|
}
|
|
}
|
|
}
|