インプットフィールド+ボタン+配列+Instantiat
InputField + Instantiate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AppearManager : MonoBehaviour
{
public GameObject[] fruitPrefabs;
public InputField inputF;
private string inputNum;
private int n;
private GameObject fruit;
public void OnAppearButtonClicked()
{
inputNum = inputF.GetComponent<InputField>().text;
n = int.Parse(inputNum);
fruit = Instantiate(fruitPrefabs[n], new Vector3(0,0,0), Quaternion.identity);
}
public void OnCloseButtonClicked()
{
Destroy(fruit);
}
}
Unity Code Memo
他のコースを見るInputField + Instantiate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AppearManager : MonoBehaviour
{
public GameObject[] fruitPrefabs;
public InputField inputF;
private string inputNum;
private int n;
private GameObject fruit;
public void OnAppearButtonClicked()
{
inputNum = inputF.GetComponent<InputField>().text;
n = int.Parse(inputNum);
fruit = Instantiate(fruitPrefabs[n], new Vector3(0,0,0), Quaternion.identity);
}
public void OnCloseButtonClicked()
{
Destroy(fruit);
}
}
インプットフィールド+ボタン+配列+Instantiat