지금 몬스터가 죽으면서 아이템 드랍하는거 구현하는 중인데 작동은 잘하는데 테스트 끝나고 자꾸 남아요 ㅠㅠ 뭐가 문제인가요?
에러: Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)
스크립트
--------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DroprateManager : MonoBehaviour
{
[System.Serializable]
public class Drops
{
public string name;
public GameObject itemPrefab;
public float dropRate;
}
public List<Drops> drops;
void OnDisable()
{
float randomNumber = UnityEngine.Random.Range(0, 100f);
List<Drops> possibleDrops = new List<Drops>();
foreach (Drops rate in drops)
{
if(randomNumber <= rate.dropRate)
{
possibleDrops.Add(rate);
}
}
if(possibleDrops.Count > 0)
{
Drops drops = possibleDrops[UnityEngine.Random.Range(0, possibleDrops.Count)];
Instantiate(drops.itemPrefab, transform.position, Quaternion.identity);
}
}
}
--------------------------------------------------------------------------------------------+
https://discussions.unity.com/t/instantiate-ondestroy/28908
감사합니다 선생님 ㅇ0ㅇ
OnDestroy는 에디터에서 실행을 끝내도 실행이 되는 코드임 따라서 사용에 주의가 필요
에러에서 OnDestroy때 오브젝트 생성했냐 물어보네 - dc App