본문 바로가기

Programming/유니티

유니티 파티클 관리

 

유니티 무한의 발판 만들기 (Unity - Infinity Vertical Jump Platform)

목표 (Subject) 무한으로 생성되는 점프 플렛폼을 만들어보자. (Creating an infinitely generated jumping platform) Platform 발판의 스크립트를 아래와 같이 작성하자 Platform.cs using System.Collections; using System.Collecti

moblieandlife.tistory.com

using UnityEngine;
using System.Collections;


public class Unit_Particle_Effect : MonoBehaviour
{
    [SerializeField] GameObject ParticleBody;

    //이팩트에 회전 요소가 있다면 subobj를 돌려준다.
    [SerializeField] Transform RotationBody;

    //파티클 본체
    [SerializeField] ParticleSystem ParticleObj;

    //파티클이 아닌 애니메이터를 사용시
    [SerializeField] Animator ParticleAnimator;

    //파티클 애니메이션은  enable하면 바로 플레이된다. 그러므로 끝나는 애니만 따로 호출한다.
    [SerializeField] string ParticleAniName;

    //파티클을 끝낼때 딜레이를 줄것인가 말것인가?
    bool mIsActiveOff = false;

    //파티클이 아닌 애니메이션을 돌리고 있는가?
    bool mIsAniOn = false;

    //게임오브젝트로만 파티클을 끄고 켤때
    bool mIsDefaultOn = false;

    //시간동안 파티클이 살아있다.
    float mTime = -1;

    public Transform GetRotationBody
    {
        get { return this.RotationBody; }
    }

    //외부에서 실행중인지 확인하고 재활용
    public bool IsDoing
    {
        get
        {
            if (ParticleAnimator != null)
            {
                if (mIsAniOn)
                {
                    return true;
                }
            }

            if (ParticleObj != null)
            {
                return ParticleObj.isPlaying;
            }

            if (ParticleAnimator == null && ParticleObj == null)
            {
                return mIsDefaultOn;
            }
            return false;
        }
    }

    public void PlayParticle(float _time = -1, bool isActiveOff = false)
    {
        mTime = _time;
        mIsActiveOff = isActiveOff;
        Unit_Particle_Play(true);

        if (mTime > 0)
        {
            StartCoroutine("TimeEnd");
        }
    }

    public void StopParticle()
    {
        Unit_Particle_Play(false);
    }

    public void PauseParticle()
    {
        if (ParticleObj != null)
        {
            ParticleObj.Pause();
        }

        if (ParticleAnimator != null)
        {
            ParticleAnimator.enabled = false;
        }
    }

    //isactiveoff는 바로 파티클을 꺼버린다.
    void Unit_Particle_Play(bool isPlay)
    {
        if (isPlay)
        {
            gameObject.SetActive(true);
        }
        else
        {
            if (mIsActiveOff)
            {
                gameObject.SetActive(false);
            }
        }

        if (ParticleObj != null)
        {
            if (ParticleObj.isPlaying != isPlay)
            {
                if (isPlay)
                {
                    ParticleObj.Play();
                }
                else
                {
                    ParticleObj.Stop();
                }
            }
        }

        if (ParticleAnimator != null)
        {
            if (isPlay)
            {
                gameObject.SetActive(false);
                gameObject.SetActive(true);
                mIsAniOn = true;
            }
            else
            {
                if (this.ParticleAniName == null)
                {
                    gameObject.SetActive(false);
                }
                else
                {
                    ParticleAnimator.enabled = true;
                    ParticleAnimator.Play(this.ParticleAniName);
                }
            }
        }

        if (ParticleObj == null && ParticleAnimator == null)
        {
            if (isPlay)
            {
                ParticleBody.SetActive(false);
                ParticleBody.SetActive(true);
                mIsDefaultOn = true;
            }
            else
            {
                ParticleBody.SetActive(false);
                mIsDefaultOn = false;
            }
        }
    }

    public void AnimationEndCall()
    {
        mIsAniOn = false;
    }

    IEnumerator TimeEnd()
    {
        yield return new WaitForSeconds(this.mTime);
        this.Unit_Particle_Play(false);
    }
}

 

 

유니티(Unity) 애드몹 부업 프로젝트 : [1] 시작

목표 아주 단순한 점프게임을 만들어서 광고를 붙이고 광고수익을 발생 시켜보는 것이 이 프로젝트의 목표입니다. 서버도 없고 단지 클라이언트로 로그라이크형의 게임을 만들것이기 때문에

moblieandlife.tistory.com

 

유니티(Unity) 배경 UV 애니메이션

목표 DoTween을 이용하여 간단한 UV 애니메이션을 만들어보자 배경 이미지 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; public class Background : MonoBehaviour

moblieandlife.tistory.com