랜덤 큐브 생성기 (Unity Learn)

2026. 1. 23. 02:17·🎮 Game Developments/Practices

탭 한 번에 소환되는 큐브 디스코!화려한 회전부터 무한 생성까지, 손끝에서 시작되는 기하학의 마법을 경험해 보세요.
지금 바로 클릭하고 터치해서 나만의 큐브 세상을 완성할 시간입니다. 언제 어디서든 즐겨보세요!

 
 
 

Random Cube Generator by HaBoong

Generator

haboong.itch.io

 
 
 
 
Unity Learn 공식 홈페이지의 Junior Programmer 과정을 진행하다가,

Unity Learn 과정 중 예제

 
간단하게 큐브의 속성을 수정해보는 과제였지만
이것 저것 만져보는게 재밌어서 뇌절해버렸다!...(3시간이나 썼다)
 
하나의 스크립트에 모든 기능이 들어가있는게 맘에 안들긴 하지만,
AI를 최소한으로 쓰고 스스로 타이핑해서 만들었다는 점에서 뿌듯하다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class Cube : MonoBehaviour
{
    public MeshRenderer Renderer;

    // 랜덤 x,y,z 변수
    public float randomX = 15;
    public float randomY = 15;
    public float randomZ = 15;

    // 랜덤 속도
    public float randomSpeed = 360;

    // 랜덤 RGBA(색)
    public float randomR, randomG, randomB, randomA;

    // 벡터 변수 생성
    private Vector3 newPos;

    // 파티클 프리팹 가져오기
    public GameObject paticlePrefab;

    // 큐브를 생성한 횟수
    private int cubeCount;

    // 소리
    public AudioSource audioSource;
    public AudioClip spawnSound;

    // UI
    [SerializeField] private TextMeshProUGUI countText;


    //--------------------------------------------------------
    //--------------------------------------------------------


    void Start()
    {
        UpdateUI();
    }
    


    void Update()
    {
        transform.Rotate(newPos, randomSpeed * Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {
            GenerateCube();
        }
    }


    //--------------------------------------------------------
    //--------------------------------------------------------
    
    // 위치 변경
    void MoveToRandomPos()
    {
        transform.position = newPos;
    }

    //--------------------------------------------------------
    //--------------------------------------------------------
    
    //랜덤화

    void Randomize()
    {
        RandomizeVector3();
        RandomizeSpeed();
        RandomizeColor();
    }



    void RandomizeVector3()
    {
        randomX = 15;
        randomY = 15;
        randomZ = 15;

        randomX = Random.Range(-randomX, randomX);
        randomY = Random.Range(-randomY, randomY);
        randomZ = Random.Range(-randomZ, randomZ);

        newPos = new Vector3(randomX, randomY, randomZ);
    }

    void RandomizeSpeed()
    {
        randomSpeed = 360;
        randomSpeed = Random.Range(0, randomSpeed);
    }

    void RandomizeColor()
    {
        randomR = Random.Range(0f, 1f);
        randomG = Random.Range(0f, 1f);
        randomB = Random.Range(0f, 1f);
        randomA = Random.Range(0f, 1f);
    }
    
    //--------------------------------------------------------
    //--------------------------------------------------------

    // 생성

    void GenerateCube()
    {
        Material material = Renderer.material;

        Randomize();

        MoveToRandomPos();
        material.color = new Color(randomR, randomG, randomB, randomA);
        transform.localScale = newPos;

        Instantiate(paticlePrefab, newPos, transform.rotation);

        AddCubeCount();

        if (audioSource != null && spawnSound != null)
        {
        audioSource.PlayOneShot(spawnSound);
        }
    }

    //--------------------------------------------------------
    //--------------------------------------------------------

    // UI
    private void UpdateUI()
    {
        if (countText != null)
        {
            countText.text = "Cubes Created: " + cubeCount;
        }
    }

    public void AddCubeCount()
    {
        cubeCount++;
        UpdateUI();
    }
}

 

using UnityEngine;

public class Destroy : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        Destroy(gameObject, 3.0f);
    }

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

파티클 프리팹에 붙인 스크립트.

 

썸네일

'🎮 Game Developments > Practices' 카테고리의 다른 글

Moonscape #1 아이디어 구상  (0) 2026.02.12
Unity 2DPhysics 스크립트로 구현하기  (0) 2026.02.02
Unity Learn 과정을 진작 할걸  (0) 2026.01.27
1BitDragon 유료 작곡 프로그램  (0) 2026.01.27
MOQI 기획, 프로토타입  (0) 2026.01.18
'🎮 Game Developments/Practices' 카테고리의 다른 글
  • Unity 2DPhysics 스크립트로 구현하기
  • Unity Learn 과정을 진작 할걸
  • 1BitDragon 유료 작곡 프로그램
  • MOQI 기획, 프로토타입
하붕
하붕
게임을 만들고 싶은 사람의 블로그
  • 하붕
    Homebody
    하붕
  • 전체
    오늘
    어제
    • 분류 전체보기 (17)
      • 🎮 Game Developments (10)
        • Practices (6)
        • Krafton Jungle Gamelab (4)
      • 🔍 Reviews (4)
        • Games (2)
        • Books (1)
        • Others (1)
      • 💡 Insights (2)
      • 🎞️ Photos (1)
  • 링크

    • Youtube
  • 인기 글

  • 태그

    Ai
    크래프톤정글
    33원정대
    게임개발
    셀레스트
    독후감
    Celeste
    게임
    게임기획
    크래프톤 정글
    게임리뷰
    itch.io
    개발자
    게임랩
    개발
    코딩
    C#
    사진
    유니티
    게임게발
    택배기사
    기획
    보더랜드
    젤다
    먼저온미래
    작곡
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
하붕
랜덤 큐브 생성기 (Unity Learn)
상단으로

티스토리툴바