객체삭제? Destroy()
2023. 3. 8. 14:41ㆍ개인적인 공부/Unity
Destroy() == Delete Game Object from the scene
() 괄호안데 조건 두가지를 작성 해야 한다.
// 지나가는 목표만 딜레이 후 삭제 하기
Destroy ( example, 1.0f);
이런식 으로 작성 하나, delay 를
[SerializeField] flaot destroyDelay = 0.5f; // 수정을 하기 위해서
Destroy (example , destoryDelay) ;
로 작성한다.
public class Delivery : MonoBehaviour
{
// 어떠한 것과 부딪히면 무엇에 부딪혔는가에 대한 정보를 얻는다.
[SerializeField] float destroyDelay = 0.5f;
bool hasPackage;
private void Start() {
Debug.Log(hasPackage);
}
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("빼-앰~!!");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Package" && !hasPackage) // 한번에 한 물품만 들수 있다.
{
Debug.Log("Package picked up");
hasPackage = true;
Destroy(other.gameObject, destroyDelay);
}
if(other.tag == "Customer" && hasPackage)
{
Debug.Log("Delivered package");
hasPackage = false;
}
}
}
'개인적인 공부 > Unity' 카테고리의 다른 글
Boost & Bump (0) | 2023.03.08 |
---|---|
Get Component (0) | 2023.03.08 |
Bool (0) | 2023.03.07 |
if 구문 (0) | 2023.03.07 |
단순 카메라 팔로우 (0) | 2023.01.23 |