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

112 lines
2.5 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "Bullet_tornado" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
using UnityEngine;
namespace G
{
/// <summary>
///
/// </summary>
public class Bullet_tornado : MonoBehaviour
{
private bool _moveStart;
private int _rndDir;
private Vector3 _targetPod;
private EntityMinion _enemy;
private Transform _parent;
private Vector3 _originScale;
private float _sinTime;
private float _moveDelay;
private void Awake()
{
_parent = transform.parent;
_originScale = transform.localScale;
}
private void Start()
{
this.GetComponent<Animation>()["tornado"].speed = 0.3f;
_enemy = transform.GetComponentInParent<EntityMinion>();
}
private void OnEnable()
{
_rndDir = Random.Range(0, 2);
_rndDir = _rndDir * 2 - 1;
_targetPod = Vector3.zero;
_moveStart = false;
_moveDelay = 0f;
_sinTime = 0f;
this.transform.parent = _parent;
this.transform.localScale = _originScale;
this.transform.position += Vector3.up * 0.1f;
}
private void Update()
{
_moveDelay += Time.deltaTime;
if (!_moveStart)
{
var monmovestat = _enemy.moveState;
if (_moveDelay < 1.2f)
{
if (monmovestat <= 0)
{
Disappear();
}
transform.localScale += Vector3.one * 0.5f * Time.deltaTime;
}
else
{
this.transform.parent = null;
_moveStart = true;
this.transform.localScale = Vector3.one * 2f;
}
return;
}
_sinTime += Time.deltaTime;
_targetPod = transform.forward * 0.8f + transform.right * 0.1f * Mathf.Cos(_sinTime * 8f) * _rndDir;
this.transform.position += _targetPod * Time.deltaTime;
this.transform.rotation = Quaternion.LookRotation(_targetPod);
Vector3 localScale = transform.localScale;
if (localScale.y > 2.2f)
{
localScale += new Vector3(-Time.deltaTime, 0f, -Time.deltaTime);
this.transform.localScale = localScale;
if (localScale.x < 1f)
{
Disappear();
}
}
else
{
this.transform.localScale += Vector3.up * 0.2f;
}
}
public void Disappear()
{
this.gameObject.SetActive(false);
this.transform.position = Vector3.one * 5f;
}
}
}