108 lines
2.7 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "SkillMachineGun" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
using UnityEngine;
namespace G
{
public class SkillFincanon : MonoBehaviour
{
public Transform beam;
private float _delay;
private CapsuleCollider _beamCollider;
private Vector3 _originScale = new Vector3(1f, 1f, 0.1f);
private bool _state;
private void Awake()
{
base.GetComponent<Animation>()["wait"].speed = 1.2f;
base.GetComponent<Animation>()["create"].speed = 0.25f;
base.GetComponent<Animation>()["destroy"].speed = 0.25f;
base.GetComponent<Animation>()["beam"].speed = 0.8f;
beam.gameObject.SetActive(false);
_beamCollider = (CapsuleCollider)beam.GetComponent<Collider>();
}
private void Start()
{
beam.GetComponent<Rigidbody>().mass = base.GetComponent<Rigidbody>().mass;
}
private void OnEnable()
{
transform.localScale = Vector3.one * 1.5f;
_state = false;
beam.localScale = Vector3.zero;
_delay = 0f;
_beamCollider.enabled = false;
_beamCollider.height = 0f;
InvokeRepeating(nameof(Shoot), 0.1f, 0.2f);
beam.gameObject.SetActive(true);
base.GetComponent<Animation>().Play("wait");
}
public void Shoot()
{
if (_delay > 0.5f)
{
_beamCollider.enabled = false;
_beamCollider.enabled = true;
}
}
private void Update()
{
_delay += Time.deltaTime;
if (_delay > 3.4f)
{
base.gameObject.SetActive(false);
transform.localScale = Vector3.zero;
beam.gameObject.SetActive(false);
CancelInvoke(nameof(Shoot));
}
else if (_delay > 2.2f)
{
base.GetComponent<Animation>().Play("destroy");
if (!_state)
{
_beamCollider.enabled = false;
_state = true;
}
beam.localScale = Vector3.Lerp(beam.localScale, Vector3.forward, Time.deltaTime * 15f);
}
else if (_delay > 1f)
{
beam.localScale = Vector3.Lerp(beam.localScale, Vector3.one, Time.deltaTime * 15f);
base.GetComponent<Animation>().Play("beam");
}
else if (_delay > 0.8f)
{
_beamCollider.height = Mathf.Lerp(_beamCollider.height, 0.7f, Time.deltaTime * 6f);
beam.localScale = Vector3.Lerp(beam.localScale, _originScale, Time.deltaTime * 6f);
_state = false;
}
else if (_delay > 0.2f)
{
if (!_state)
{
transform.parent = null;
_state = true;
}
base.GetComponent<Animation>().Play("create");
}
}
}
}