티스토리 뷰

728x170

Invoke()로 1초마다 함수 실행

1초마다 Spawn 함수 실행

using UnityEngine;

public class MonsterSpwaner : MonoBehaviour
{
    public GameObject monsterPrefab;

    void Start()
    {
        Invoke("Spawn", 1);
    }

    void Spawn()
    {
        Instantiate(monsterPrefab);
    }

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

 

2초 뒤, 1초마다 함수 호출

using UnityEngine;

public class MonsterSpwaner : MonoBehaviour
{
    public GameObject monsterPrefab;

    void Start()
    {
        InvokeRepeating("Spawn", 2, 1);
    }

    void Spawn()
    {
        Instantiate(monsterPrefab);
    }

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

 

그리드형

'개발 > Unity Engine' 카테고리의 다른 글

Unity Engine의 .gitignore에 추가할 파일 이름들  (0) 2024.12.02
공지사항
최근에 올라온 글
최근에 달린 댓글
링크
«   2025/12   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함
세로형