47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
|
||
|
|
public class ShootButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||
|
|
{
|
||
|
|
[SerializeField] private float rotationLimit = 40;
|
||
|
|
[SerializeField] private float rotationSpeed = 15;
|
||
|
|
private bool rotate = false;
|
||
|
|
private bool isDisabled = false;
|
||
|
|
|
||
|
|
public PlayerController playerController;
|
||
|
|
|
||
|
|
void FixedUpdate()
|
||
|
|
{
|
||
|
|
float targetRotate = rotate ? rotationLimit : 0f;
|
||
|
|
Quaternion target = Quaternion.Euler(targetRotate, 0, 0);
|
||
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * rotationSpeed);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerDown(PointerEventData pointerEventData)
|
||
|
|
{
|
||
|
|
if (isDisabled) return;
|
||
|
|
|
||
|
|
rotate = true;
|
||
|
|
|
||
|
|
if (playerController != null)
|
||
|
|
{
|
||
|
|
Vector2? input = (GameSettings.IsMobile && playerController.joystick != null)
|
||
|
|
? playerController.joystick.GetInput()
|
||
|
|
: null;
|
||
|
|
|
||
|
|
playerController.Shoot(input);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerUp(PointerEventData pointerEventData)
|
||
|
|
{
|
||
|
|
rotate = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 외부에서 호출
|
||
|
|
public void SetDisabled(bool disabled)
|
||
|
|
{
|
||
|
|
isDisabled = disabled;
|
||
|
|
if (disabled) rotate = false;
|
||
|
|
}
|
||
|
|
}
|