728x90
1. Sprite 5가지 추가
2. Prefabs 복제 5개
3. Item2 open prefabs
아이템 변경
4. ItemGenerator 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemGenerator : MonoBehaviour
{
public float genStartTime;
public float genDelayTime;
//프리팹 배열로 만들기
public GameObject[] itemPrefabs;
// Start is called before the first frame update
void Start()
{
Vector3 tempPosition = new Vector3(0f, 2f, 0f);
//Instantiate(itemPrefab, tempPosition, Quaternion.identity);
//for (int i = 0; i < 10; i++)
//{
// float x = Random.Range(-6f, 6f);
// float y = Random.Range(-4.3f, 4.3f);
// Vector3 randPos = new Vector3(x, y, 0f);
// Instantiate(itemPrefab, randPos, Quaternion.identity);
//}
InvokeRepeating("CreateItem", genStartTime, genDelayTime);
}
void CreateItem()
{
float x = Random.Range(-6f, 6f);
float y = Random.Range(-4.3f, 4.3f);
Vector3 randPos = new Vector3(x, y, 0f);
int itemIndex = Random.Range(0, itemPrefabs.Length);
Instantiate(itemPrefabs[itemIndex], randPos, Quaternion.identity);
}
// Update is called once per frame
void Update()
{
}
}
5. GameManager에 size 5개 추가 (자물쇠 잠그고 전체 드레그)
'Unity > 코인먹기 게임' 카테고리의 다른 글
[유니티] 랜덤하게 코인 생성하기+게임종료 장면 추가하기 (0) | 2021.04.26 |
---|---|
[유니티] 코인 prefab 만들기 (0) | 2021.04.25 |
[유니티] 캐릭터가 화면을 넘어가지 않도록 만들기 (0) | 2021.04.25 |
[유니티] 2D 코인 먹기 게임 만들기 (0) | 2021.04.24 |
댓글