jojoburaki
@jojoburaki

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

unityですオブジェクトが5個以上増えないようにして一つ消えると一つ生成できるようなプログラムを教えてください

Q&A

Closed

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

public class a : MonoBehaviour
{
public GameObject[] balls ; // 表示するオブジェクトのプレハブ
public float spacing = 2f; // オブジェクト間の間隔
private int number;

void Start()
{

}

private void Update()
{

// スペースキーが押されたら
if (Input.GetKeyDown(KeyCode.Space))
{

{

number = Random.Range (1, 1000);
// オブジェクトを生成する位置を計算
Vector3 spawnPosition = transform.position;
spawnPosition.x += spacing * transform.childCount;

// オブジェクトを生成
if(number <= 6)
{
Instantiate(balls[1], spawnPosition, Quaternion.identity, transform);

        }
    else if(number <= 10)
        {
          Instantiate(balls[2], spawnPosition, Quaternion.identity, transform);
          
        }
        else if(number <= 12)
        {
          Instantiate(balls[3], spawnPosition, Quaternion.identity, transform);
          
        }
        else if(number <= 13)
        {
          Instantiate(balls[4], spawnPosition, Quaternion.identity, transform);
          
        }
        else
        {
         
          Instantiate(balls[0], spawnPosition, Quaternion.identity, transform); 
        }

}
}
}
}
ここに入れたいのですがどのようにすればよいですか?

0

No Answers yet.

Your answer might help someone💌