Snippets

David Fraj Crear Cubos en Unity3D

Created by David Fraj
using UnityEngine;
using System.Collections;

public class CrearCubos : MonoBehaviour {
    //Me creo una propiedad para contar
	public int contador;
	public bool incrementaLuz;
	public TextMesh pantalla;
	public bool CubosConstruidos=false;

	// Use this for initialization
	void Start () {
		this.contador = 0;
		this.incrementaLuz = true;
		pantalla = (TextMesh)GameObject.Find("Text_reciver").GetComponent<TextMesh>();
		pantalla.text = "hola";
		//this.construirCubos();
	}
	
	// Update is called once per frame
	void Update () {
		//Creamos una variable, para saber cuando construir los cubos
		//int tiempo=1000;
		//Si el contador acaba llegando a ese tiempo, construimos los cubos
		//if(this.contador == tiempo){
			//this.construirCubos();
		//}

		//Recogemos el GameObject llamado "Luz"
		//GameObject luz = GameObject.Find ("Luz");	

		//Miramos a ver si incrementamos o no la intensidad de luz
		/*if (incrementaLuz) {
			luz.GetComponent<Light> ().intensity += 0.01f;
		} else {
			luz.GetComponent<Light> ().intensity -= 0.01f;
		}*/

		//Miramos a ver si tenemos que apagar luces o encenderlas.
		/*if(luz.GetComponent<Light>().intensity <0f){
			this.incrementaLuz=true;
			Debug.Log("Cambiamos a true");
		}

		if(luz.GetComponent<Light>().intensity > 8f){
			this.incrementaLuz=false;
			Debug.Log("Cambiamos a false");
		}*/

		//Siempre incrementamos el contador
		this.contador++;

		//pantalla.text = this.contador.ToString();
		//this.pantalla.text = contador.ToString();
		this.pantalla.text = Time.realtimeSinceStartup.ToString();

		if (Time.time > 10) {
			if(CubosConstruidos==false){
				this.construirCubos();
				CubosConstruidos=true;
			}
		}


	}

	void construirCubos(){
		float posx;
		float posy;
		float desplazamiento = 0.6f;
		for (int y = 0; y < 50; y++) {
			for (int x = 0; x < 20; x++) {
				GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
				
				cube.AddComponent<Rigidbody>();
				cube.AddComponent<Rotar>();
				
				posx=x+ (float)(desplazamiento*x) - 10;
				posy=y+ (float)(desplazamiento*y) + 3;
				cube.transform.position = new Vector3(posx, posy, 0);
			}
		}
	}
	
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.