2025-05-18 01:04:31 +08:00

106 lines
2.6 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-08-28
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "SpiritSword3" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G
{
using UnityEngine;
public class SpiritSword3 : SpiritSword
{
private Transform[] _swords = new Transform[4];
private void OnEnable()
{
Reset();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer != GameLayer.UnitLayer || _homing || _oldTarget == other.transform)
{
return;
}
_swords[_swordIndex].GetComponent<SpiritSword_p3>().FireSword(other.transform);
_oldTarget = other.transform;
_swordIndex = (_swordIndex + 1) % _swordCount;
_hitCount++;
_collider.enabled = false;
_startDelay = 0f;
_homing = true;
if (_hitCount >= _hitCountMax)
{
_homing = false;
this.gameObject.SetActive(false);
_transform.position = Vector3.up * 31f;
for (int i = 0; i < 4; i++)
{
_swords[i].GetComponent<SpiritSword_p3>().FinishSword();
}
}
}
private void Update()
{
if (!_createFinish)
{
if (_startDelay > 0.2f)
{
_startDelay = 0f;
if (_swords[_createIndex] == null)
{
_swords[_createIndex] = Object.Instantiate(sword, _transform.position - _transform.forward, _transform.rotation, _transform);
_swords[_createIndex].GetComponent<Rigidbody>().mass = _power;
_swords[_createIndex].GetComponent<SpiritSword_p3>().SetPos(_createIndex);
}
else
{
_swords[_createIndex].SetPositionAndRotation(_transform.position - _transform.forward, _transform.rotation);
_swords[_createIndex].gameObject.SetActive(true);
}
if (_createIndex < 3)
{
_createIndex++;
}
else
{
_createFinish = true;
}
}
else
{
_startDelay += Time.deltaTime;
}
}
else if (_startDelay > 0.3f)
{
_homing = false;
_collider.enabled = true;
_startDelay = -1f;
}
else if (_startDelay > -1f)
{
_startDelay += Time.deltaTime;
}
else
{
_startDelay -= Time.deltaTime;
if (_startDelay < -2f)
{
_collider.enabled = false;
_collider.enabled = true;
_oldTarget = null;
}
}
_transform.SetPositionAndRotation(_cha1.position + Vector3.up * 0.1f, Quaternion.Lerp(_transform.rotation, _cha1.rotation, Time.deltaTime * 3f));
}
}
}