ren811

CenarioControl.cs

Dec 13th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class CenarioControl : MonoBehaviour {
  6.    
  7.     public GameObject casa = null;
  8.     public GameObject plano = null;
  9.    
  10.     private int CurrentPlane = 0;
  11.     private int lastInstance = 62;
  12.    
  13.     private float nextCasaInstantiate = 9.4f;
  14.    
  15.     GameObject casaPequena;
  16.     GameObject terreno;
  17.     List<GameObject> terrenos;
  18.    
  19.     // Use this for initialization
  20.     void Start ()
  21.     {
  22.        
  23.  
  24.         int i = 1;
  25.         int x = 0;
  26.         while (i <= 7)
  27.         {
  28.             InstanciaCasa(new Vector3(36, 0, i*9));
  29.             InstanciaCasa(new Vector3(52, 0, i*9));
  30.             i++;
  31.         }
  32.         terrenos = new List<GameObject>();
  33.         while (x < 7)
  34.         {
  35.             terrenos.Add((GameObject)Instantiate(plano, new Vector3(44, 0, (x * 10 + 2)), Quaternion.identity));
  36.             x++;
  37.         }
  38.         terrenos.Add((GameObject)Instantiate(plano, new Vector3(44, 0, -30), Quaternion.identity));
  39.     }
  40.    
  41.     void InstanciaCasa(Vector3 pos)
  42.     {
  43.         casaPequena = (GameObject)Instantiate(casa, pos, Quaternion.identity);
  44.         if (casaPequena.transform.position.x > 50)
  45.         {
  46.             casaPequena.transform.Rotate(0,270,0);
  47.         }
  48.         else
  49.         {
  50.             casaPequena.transform.Rotate(0,90,0);
  51.         }
  52.     }
  53.    
  54.     // Update is called once per frame
  55.     void Update ()
  56.     {
  57.         if (gameObject.transform.position.z >= nextCasaInstantiate)
  58.         {
  59.             InstanciaCasa(new Vector3(52,0,gameObject.transform.position.z + 60));
  60.             InstanciaCasa(new Vector3(36,0,gameObject.transform.position.z + 60));
  61.             nextCasaInstantiate += 9;
  62.         }
  63.         if (CurrentPlane > 6) { CurrentPlane = 0; }
  64.         if (gameObject.transform.position.z >= terrenos[CurrentPlane+1].transform.position.z)
  65.         {
  66.             terrenos[CurrentPlane].transform.Translate(0, 0, 60);
  67.             Debug.Log("Current Plane: " + CurrentPlane);
  68.             CurrentPlane++;
  69.             lastInstance += 10;
  70.             if (CurrentPlane > 8)
  71.             {
  72.                 Debug.Log("Current Plane: " + CurrentPlane);
  73.                 CurrentPlane = 0;
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment