57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
namespace UnityTemplateProjects
|
|
{
|
|
public class BulletProxy : MonoBehaviour
|
|
{
|
|
[SerializeField] private TrailRenderer tr;
|
|
[SerializeField] private ParticleSystem particles;
|
|
private float oldTime;
|
|
private ParticleSystem instPart;
|
|
|
|
private void Awake()
|
|
{
|
|
oldTime = tr.time;
|
|
if(particles)
|
|
{
|
|
particles.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
tr.time = 0;
|
|
if(instPart)
|
|
{
|
|
var main = instPart.main;
|
|
main.loop = false;
|
|
//main.duration = 0.2f;
|
|
Destroy(instPart.gameObject, 2f);
|
|
instPart = null;
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
tr.time = oldTime;
|
|
if(instPart)
|
|
{
|
|
Destroy(instPart.gameObject);
|
|
}
|
|
if(particles)
|
|
{
|
|
instPart = Instantiate(particles, transform.position, quaternion.identity);
|
|
instPart.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(instPart)
|
|
{
|
|
instPart.transform.position = transform.position;
|
|
}
|
|
}
|
|
}
|
|
} |