113 lines
2.4 KiB
C#
113 lines
2.4 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-08-28
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "SpiritSword_p" company="Kimch"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G
|
|||
|
{
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class SpiritSword_p1 : MonoBehaviour
|
|||
|
{
|
|||
|
private bool fireon;
|
|||
|
|
|||
|
private Transform mytransform;
|
|||
|
|
|||
|
private Transform target;
|
|||
|
|
|||
|
private Vector3 targetpos;
|
|||
|
|
|||
|
private Vector3 directionVector;
|
|||
|
|
|||
|
|
|||
|
private Collider mycollider;
|
|||
|
|
|||
|
private TrailRenderer mytrail;
|
|||
|
|
|||
|
private float _time;
|
|||
|
private float _speed = 1.8f;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
mytransform = this.transform;
|
|||
|
mycollider = this.GetComponent<Collider>();
|
|||
|
mytrail = GetComponent<TrailRenderer>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
mytransform.localScale = Vector3.right + Vector3.up;
|
|||
|
mycollider.enabled = false;
|
|||
|
_time = 0f;
|
|||
|
}
|
|||
|
|
|||
|
public void FireSword(Transform enemy)
|
|||
|
{
|
|||
|
mycollider.enabled = true;
|
|||
|
mytransform.parent = null;
|
|||
|
fireon = true;
|
|||
|
target = enemy;
|
|||
|
mytrail.enabled = true;
|
|||
|
}
|
|||
|
|
|||
|
private void OnTriggerEnter(Collider other)
|
|||
|
{
|
|||
|
if (other.transform == target)
|
|||
|
{
|
|||
|
mycollider.enabled = false;
|
|||
|
mytrail.enabled = false;
|
|||
|
fireon = false;
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (fireon)
|
|||
|
{
|
|||
|
Vector3 position = mytransform.position;
|
|||
|
if (target && position.y > 0f)
|
|||
|
{
|
|||
|
if (_time < 2f)
|
|||
|
{
|
|||
|
_time += Time.deltaTime;
|
|||
|
}
|
|||
|
|
|||
|
targetpos = target.position;
|
|||
|
directionVector = targetpos - mytransform.position;
|
|||
|
if (directionVector != Vector3.zero)
|
|||
|
{
|
|||
|
mytransform.rotation = Quaternion.Lerp(mytransform.rotation, Quaternion.LookRotation(directionVector), 20f * _time * Time.deltaTime);
|
|||
|
}
|
|||
|
mytransform.position += mytransform.forward * Time.deltaTime * _speed;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
mycollider.enabled = false;
|
|||
|
mytrail.enabled = false;
|
|||
|
fireon = false;
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Vector3 localScale = mytransform.localScale;
|
|||
|
if (localScale.z < 1f)
|
|||
|
{
|
|||
|
mytransform.localScale += Vector3.forward * Time.deltaTime * 6f;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
mytransform.localScale = Vector3.one;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|