110 lines
2.8 KiB
C#
110 lines
2.8 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-08-28
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "SpiritSword2" company="Kimch"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G
|
|
{
|
|
using UnityEngine;
|
|
|
|
public class SpiritSword2 : SpiritSword
|
|
{
|
|
const int MAX_SWORD_COUNT = 1;
|
|
|
|
private Transform[] _swords = new Transform[MAX_SWORD_COUNT];
|
|
|
|
private void OnDisable()
|
|
{
|
|
Reset();
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.layer != GameLayer.UnitLayer || _homing || _oldTarget == other.transform)
|
|
{
|
|
return;
|
|
}
|
|
_swords[_swordIndex].GetComponent<SpiritSword_p2>().FireSword(other.transform);
|
|
_oldTarget = other.transform;
|
|
_collider.enabled = false;
|
|
|
|
_swordIndex = (_swordIndex + 1) % MAX_SWORD_COUNT;
|
|
_hitCount++;
|
|
_startDelay = 0f;
|
|
_homing = true;
|
|
|
|
if (_hitCount >= _hitCountMax)
|
|
{
|
|
_homing = false;
|
|
this.gameObject.SetActive(false);
|
|
_transform.position = Vector3.up * 31f;
|
|
for (int i = 0; i < MAX_SWORD_COUNT; i++)
|
|
{
|
|
_swords[i].GetComponent<SpiritSword_p2>().FinishSword();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_createFinish)
|
|
{
|
|
if (_startDelay > 0.2f)
|
|
{
|
|
_startDelay = 0f;
|
|
if (_swords[_createIndex] == null)
|
|
{
|
|
_swords[_createIndex] = Object.Instantiate(sword, _transform.position, _transform.rotation);
|
|
_swords[_createIndex].GetComponent<Rigidbody>().mass = _power;
|
|
_swords[_createIndex].forward = Vector3.up + _transform.forward * 0.6f;
|
|
_swords[_createIndex].parent = _transform;
|
|
}
|
|
else
|
|
{
|
|
_swords[_createIndex].GetComponent<Rigidbody>().mass = _power;
|
|
_swords[_createIndex].position = _transform.position;
|
|
_swords[_createIndex].rotation = _transform.rotation;
|
|
_swords[_createIndex].gameObject.SetActive(true);
|
|
_swords[_createIndex].forward = Vector3.up + _transform.forward * 0.6f;
|
|
}
|
|
if (++_createIndex >= MAX_SWORD_COUNT)
|
|
{
|
|
_createFinish = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_startDelay += Time.deltaTime;
|
|
}
|
|
}
|
|
else if (_startDelay > 0.4f)
|
|
{
|
|
_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.position = _cha1.position + Vector3.up * 0.2f;
|
|
_transform.rotation = Quaternion.Lerp(_transform.rotation, _cha1.rotation, Time.deltaTime * 3f);
|
|
}
|
|
}
|
|
} |