본문 바로가기
개발일지/게임개발

Unity effect maker 제작

by 라이티아 2025. 4. 29.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
[System.Serializable]
public class EffectPair
{
    public GameObject effect;
    public Vector3 position;
}

public class instanceEffect : MonoBehaviour
{
    public List<EffectPair> effectPairs = new List<EffectPair>();
    public void InstanceEffect(int num)
    {
        var pair = effectPairs[num];
        GameObject instance = GameObject.Instantiate(pair.effect, pair.position, Quaternion.identity);
        Destroy(instance, 3f);
    }
    public void InstanceEffect(int num, float desTime)
    {
        var pair = effectPairs[num];
        GameObject instance = GameObject.Instantiate(pair.effect, pair.position, Quaternion.identity);
        Destroy(instance, desTime);
    }
}

현재 구조는 effectpair class가 저장하고 있는 이펙트 프리팹, 위치값을 사용하여 원하는 위치에 이펙트를 생성하는 구조이다

 

이때 InstanceEffect(int a)로 원하는 위치에 쉽게 이펙트를 소환하는 것이 목표다

 

public List<EffectPair> effectPairs = new List<EffectPair>();
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        else
        {
            Destroy(this.gameObject);
        }
    }

추가로 싱글톤을 넣어 어디서든 호출 할 수 있게 한다