Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
気体分子をインスタンス化するスクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GenerateMolecule : MonoBehaviour {
public GameObject moleculeParent;
public GameObject moleculeCounter;
public List<GameObject> type = new List<GameObject>();
Text moleculeCounterText;
float intervalTime = 0.5f;
float time;
void Start(){
moleculeCounterText = moleculeCounter.GetComponent<Text>();
}
void Update(){
InstantiateMolecules();
SetMoleculeCounterText();
}
void InstantiateMolecules(){
time += Time.deltaTime;
if (time >= intervalTime){
int index = Random.Range(0, type.Count);
GameObject molecule = Instantiate(type[index], moleculeParent.transform.position, Quaternion.identity);
molecule.transform.SetParent(moleculeParent.transform);
time = 0f;
}
}
void SetMoleculeCounterText(){
int moleculeCount = moleculeParent.transform.childCount;
moleculeCounterText.text = "Molecule Count : " + moleculeCount.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.