Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created May 29, 2018 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/dc24494721a6dc1b6db1782c74e1f554 to your computer and use it in GitHub Desktop.
Save todorok1/dc24494721a6dc1b6db1782c74e1f554 to your computer and use it in GitHub Desktop.
気体分子をインスタンス化するスクリプト
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