updated
This commit is contained in:
74
Assets/Scripts/Enemies/SwarmAnimator.cs
Normal file
74
Assets/Scripts/Enemies/SwarmAnimator.cs
Normal file
@ -0,0 +1,74 @@
|
||||
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";
|
||||
|
||||
[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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/SwarmAnimator.cs.meta
Normal file
11
Assets/Scripts/Enemies/SwarmAnimator.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 735497967e6cfdf4090b8092757c54a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user