프로그래밍

[Unity3D] TimeScale 의 영향을 받지 않는 particale

tedhong 2023. 2. 9. 14:23
2014-10-27 글쓴이 TED HONG

[Unity3D] TimeScale 의 영향을 받지 않는 particale

파티클은 유니티 엔진에서 컨트롤을 하기 때문에

TimeScale 이 0인 경우에는 동작하지 않는다.

이를 해결 하려면 다음 스크립트를 파티클 오브젝트에 추가한다.

 

 

using UnityEngine;
using System.Collections;

public class ParticaleAnimator : MonoBehaviour
{

    private void Awake()
    {
        particle = GetComponent<ParticleSystem>();
    }

    // Use this for initialization
    void Start()
    {
        lastTime = Time.realtimeSinceStartup;
    }

    // Update is called once per frame
    void Update()
    {

        float deltaTime = Time.realtimeSinceStartup - (float)lastTime;

        particle.Simulate(deltaTime, true, false); //last must be false!!

        lastTime = Time.realtimeSinceStartup;
    }

    private double lastTime;
    private ParticleSystem particle;

}