OldBlueWater/BlueWater/Assets/02.Scripts/Player/Cannon.cs

45 lines
1.4 KiB
C#
Raw Normal View History

using System;
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;
[Title("캐논 발사 카메라 효과")]
[SerializeField] private float cameraShakePower = 0.5f;
[SerializeField] private float cameraShakeDuration = 0.5f;
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");
}
public void Fire(float chargingGauge)
{
VisualFeedbackManager.Inst.CameraShake(CameraManager.Inst.OceanCamera.BaseShipCam, cameraShakePower, cameraShakeDuration);
var projectile = Instantiate(projectileObj, firePos.position, Quaternion.identity);
projectile.GetComponent<Rigidbody>().AddForce(transform.forward * (chargingGauge * speed));
}
}
}