178 lines
4.1 KiB
C#
178 lines
4.1 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-02
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "SkillGuard" company="Kimch"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 召唤守卫
|
|
/// </summary>
|
|
[RequireComponent(typeof(SkillBase))]
|
|
public class SkillGuard : MonoBehaviour
|
|
{
|
|
private Collider _collider;
|
|
|
|
private float _power;
|
|
|
|
private Vector3 _rndPos;
|
|
|
|
private Quaternion _rotate;
|
|
|
|
private Transform _cha1;
|
|
|
|
public Transform ef_splash;
|
|
public Transform pt_body;
|
|
|
|
private Transform _cloneSplash;
|
|
|
|
private Animation _animation;
|
|
|
|
private bool _attackStart = true;
|
|
|
|
private Vector3 _scaleReduce;
|
|
|
|
private int _attackCount;
|
|
|
|
|
|
public AudioClip snd_attack;
|
|
|
|
public float lifeTime
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
_collider = this.GetComponent<Collider>();
|
|
_animation = this.GetComponent<Animation>();
|
|
|
|
_animation["junwui_appear"].speed = 0.2f;
|
|
_animation["junwui_attack"].speed = 0.3f;
|
|
_animation["junwui_idle"].speed = 0.2f;
|
|
_animation["junwui_finish"].speed = 0.2f;
|
|
_animation["junwui_appear"].layer = 2;
|
|
_animation["junwui_attack"].layer = 1;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_cha1 = GameObject.FindWithTag("Player").transform;
|
|
InvokeRepeating(nameof(SetRndPosition), 0f, 2f);
|
|
_scaleReduce = new Vector3(1f, -1f, 1f);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_animation.Stop();
|
|
_collider.enabled = true;
|
|
_animation.Play("junwui_appear");
|
|
_animation.Play("junwui_idle");
|
|
pt_body.particleEmitter().emit = true;
|
|
transform.localScale = Vector3.one * 0.5f;
|
|
_attackCount = 0;
|
|
}
|
|
|
|
public void SetRndPosition()
|
|
{
|
|
_rndPos = Random.onUnitSphere * 0.4f + _cha1.position;
|
|
_rndPos.y = 0f;
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!_attackStart && other.gameObject.layer == GameLayer.UnitLayer)
|
|
{
|
|
_animation.Play("junwui_attack");
|
|
_attackStart = true;
|
|
_rotate = Quaternion.LookRotation(other.transform.position - transform.position);
|
|
}
|
|
}
|
|
|
|
public void SetDamage(float _damage)
|
|
{
|
|
_power = _damage;
|
|
}
|
|
|
|
private void Attack()
|
|
{
|
|
this.GetComponent<AudioSource>().clip = snd_attack;
|
|
this.GetComponent<AudioSource>().Play();
|
|
if (_cloneSplash == null)
|
|
{
|
|
_cloneSplash = Object.Instantiate(ef_splash, transform);
|
|
_cloneSplash.GetComponent<Rigidbody>().mass = _power;
|
|
}
|
|
else
|
|
{
|
|
_cloneSplash.gameObject.SetActive(true);
|
|
}
|
|
_collider.enabled = false;
|
|
_attackCount++;
|
|
if (false && _attackCount >= 12)
|
|
{
|
|
var finish = _animation.PlayQueued("junwui_finish");
|
|
finish.speed = 0.2f;
|
|
finish.layer = 1;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (lifeTime > 0f)
|
|
{
|
|
lifeTime -= Time.deltaTime;
|
|
if (lifeTime <= 0f)
|
|
{
|
|
_collider.enabled = false;
|
|
/*finish =*/
|
|
_animation.Play("junwui_finish");
|
|
//finish.speed = 0.2f;
|
|
//finish.layer = 1;
|
|
}
|
|
}
|
|
|
|
if (_animation.IsPlaying("junwui_finish"))
|
|
{
|
|
transform.localScale -= _scaleReduce * Time.deltaTime * 3f;
|
|
Vector3 localScale = transform.localScale;
|
|
if (localScale.x < 0.1f)
|
|
{
|
|
transform.position = Vector3.one * 20f;
|
|
//pt_body.particleEmitter().emit = false;
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
else if (_animation.IsPlaying("junwui_appear"))
|
|
{
|
|
_attackStart = true;
|
|
}
|
|
else if (_animation.IsPlaying("junwui_attack"))
|
|
{
|
|
transform.rotation = Quaternion.Lerp(transform.rotation, _rotate, Time.deltaTime * 8f);
|
|
_attackStart = true;
|
|
}
|
|
else if (_animation.IsPlaying("junwui_idle"))
|
|
{
|
|
if (_attackStart)
|
|
{
|
|
_attackStart = false;
|
|
_collider.enabled = true;
|
|
}
|
|
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(_rndPos - transform.position), Time.deltaTime * 2f);
|
|
transform.position = Vector3.Lerp(transform.position, _rndPos, Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
}
|