42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
|
using UnityEngine;
|
|||
|
|
|||
|
public class MeteorEffectController : ParticleCleaner
|
|||
|
{
|
|||
|
public float radius { get; private set; }
|
|||
|
private float _distToPitch;
|
|||
|
private GameObject _airHub;
|
|||
|
private GameObject _groundHub;
|
|||
|
private Transform _ball;
|
|||
|
|
|||
|
protected override void Awake()
|
|||
|
{
|
|||
|
base.Awake();
|
|||
|
_airHub = transform.Find("Air").gameObject;
|
|||
|
_groundHub = transform.Find("Ground").gameObject;
|
|||
|
_ball = transform.Find("Ball");
|
|||
|
var sphereCollider = _ball.GetComponent<SphereCollider>();
|
|||
|
radius = sphereCollider.radius * _ball.localScale.y;
|
|||
|
_distToPitch = 1f / (2 * Mathf.PI * radius) * 360f;
|
|||
|
}
|
|||
|
|
|||
|
public void SetRotationByDistance(float distance)
|
|||
|
{
|
|||
|
_ball.localRotation = Quaternion.Euler(_distToPitch * distance, 0f, 0f);
|
|||
|
}
|
|||
|
|
|||
|
public void SetOnGround(bool isOnGround)
|
|||
|
{
|
|||
|
_airHub.SetActive(!isOnGround);
|
|||
|
_groundHub.SetActive(isOnGround);
|
|||
|
}
|
|||
|
|
|||
|
protected override void EnableComponents(bool isEnable)
|
|||
|
{
|
|||
|
base.EnableComponents(isEnable);
|
|||
|
if (isEnable)
|
|||
|
{
|
|||
|
SetOnGround(false);
|
|||
|
_ball.localRotation = Quaternion.identity;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|