Created
May 29, 2018 12:16
-
-
Save todorok1/dc24494721a6dc1b6db1782c74e1f554 to your computer and use it in GitHub Desktop.
気体分子をインスタンス化するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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