유니티 연습.!
using UnityEngine;
using System.Collections;
using System.Collections.Generic; //_using list.
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
// using.
public GameObject[] blockPrefab = null;
public List<GameObject> blockList = null;
// using static
public static int Max = 0;
public static int nGood = 0;
public static int nNum = 10;
// Use this for initialization
void Start () {
for (int i = 0; i < nNum; i++) {
NewBlock (i);
Max++;
}
}
// Update is called once per frame
void Update () {
}
// using make functions
public void NewBlock(int y) {
int rand = Random.Range (0,2);
Vector2 pos = new Vector2 (0, y);
GameObject block = Instantiate (blockPrefab [rand], pos, Quaternion.identity) as GameObject;
blockList.Add (block);
// box collider 2d. setting.
// constaints -> dont move.
}
// using make color Arrows
public void ArrowBtn(string arrow_color) {
Debug.Log (arrow_color+"Btn");
if(blockList[nGood].tag == arrow_color) {
Debug.Log ("같은 색상.");
NewBlock (Max);
Max++;
blockList [nGood].SetActive (false);
nGood++;
if (nGood > 20) {
print ("New_Game");
SceneManager.LoadScene ("2d");
Max = nGood = 0;
}
GameObject.Destroy(blockList[nGood-1], 3f);
//Destroy (this.gameObject, 5f);
//blockList.RemoveAt (blockList.Count-1);
//blockList.Remove (blockList);
//blockList [0].transform.position.x = -10;
//blockList.RemoveAll (blockList);
//GameObject o=((Transform)Instantiate(blockPrefab)).gameObject;
//GameObject.Destroy(o.gameObject);
//Destroy (blockList);
//blockList.transform.position.y = 100;
} else {
Debug.Log ("다른 색상.");
}
}
}