This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Enemies/SwarmAnimator.cs

75 lines
1.6 KiB
C#
Raw Normal View History

2023-04-08 07:23:11 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
[ExecuteAlways]
public class SwarmAnimator : MonoBehaviour
{
[SerializeField]
private VisualEffect vfx;
private Vector3 currentPosition;
private Vector3 previousPosition;
[SerializeField]
private Rigidbody rb;
//[SerializeField]
//private string parameterName = "DeltaVector";
2023-04-08 07:23:11 +02:00
[SerializeField]
private Vector3 avoidancePosDefault;
[SerializeField]
private float explodeDuration = 1.0f;
private float dur = 0f;
private bool isExploding = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
previousPosition = currentPosition;
currentPosition = transform.position;
Vector3 velocity = (currentPosition - previousPosition) ;
vfx.SetVector3("DeltaVector", velocity);
if (Input.GetKeyDown(KeyCode.Space))
{
Explode();
}
if (isExploding)
{
if(dur> explodeDuration)
{
StopExplode();
}
dur += Time.deltaTime;
}
}
void Explode()
{
vfx.SetVector3("Avoid", transform.position);
this.isExploding = true;
dur = 0;
//Wait a sec then stop.
}
void StopExplode()
{
vfx.SetVector3("Avoid", avoidancePosDefault);
this.isExploding = false;
vfx.Stop();
}
private void FixedUpdate()
{
}
}