Files
BITFALL/Assets/Plugins/FImpossible Creations/Plugins - Level Design/PGG/Demos - PGG/Demos Assets/Scripts/SimpleProjectile.cs

48 lines
1.3 KiB
C#
Raw Normal View History

2023-11-30 00:23:23 +08:00
using UnityEngine;
namespace FIMSpace.Generating
{
public class SimpleProjectile : MonoBehaviour
{
public Vector3 Velocity;
private Rigidbody rig;
private void Start()
{
rig = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if (rig.detectCollisions)
rig.velocity = Velocity;
else
rig.velocity = Vector3.zero;
}
private void OnCollisionEnter(Collision collision)
{
SimpleEnemy enemy = collision.transform.GetComponent<SimpleEnemy>();
if (enemy)
{
enemy.Damage(1);
Deactivate();
}
else
{
if (collision.transform.GetComponent<CharacterController>() == null)
{
Deactivate();
}
}
}
private void Deactivate()
{
rig.detectCollisions = false;
ParticleSystem ps = GetComponentInChildren<ParticleSystem>();
ps.Stop(true, ParticleSystemStopBehavior.StopEmitting);
GetComponentInChildren<MeshRenderer>().enabled = false;
Destroy(gameObject, 3f);
}
}
}