ren811

Tigelas.cs

Dec 13th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Tigelas : MonoBehaviour {
  5.    
  6.     public GameObject bowl = null;
  7.    
  8.     public float _NextSpawn = 2f;
  9.     public float Interval = 1f;
  10.     public int contador = 0;
  11.    
  12.     GameObject tigela;
  13.    
  14.     public enum Estado
  15.     {
  16.         NONE = 0,
  17.         RANDOM = 1,
  18.         LINHA = 2,
  19.         DIAGONAL_LEFT = 3,
  20.         DIAGONAL_RIGHT = 4,
  21.     }
  22.    
  23.     public Estado estadoAtual = Estado.RANDOM;
  24.     // Use this for initialization
  25.     void Start ()
  26.     {
  27.         estadoAtual = SorteiaEstado();
  28.     }
  29.    
  30.     Estado SorteiaEstado()
  31.     {
  32.         int Rand = Random.Range (0,4);
  33.         if (Rand == 0) { return Estado.NONE; }
  34.         if (Rand == 1) { return Estado.RANDOM; }
  35.         if (Rand == 2) { return Estado.LINHA; }
  36.         if (Rand == 3) { return Estado.DIAGONAL_LEFT; }
  37.         if (Rand == 4) { return Estado.DIAGONAL_RIGHT; }
  38.         else return Estado.NONE;
  39.     }
  40.    
  41.     void InstanciaTigela(float X)
  42.     {
  43.         tigela = (GameObject)Instantiate(bowl, new Vector3(X, 0, Camera.main.transform.position.z + 20), Quaternion.identity);
  44.         tigela.transform.Rotate(-90f, 0f, 0f);
  45.         _NextSpawn += Interval;
  46.     }
  47.  
  48.     void Update()
  49.     {  
  50.         if (Time.time >= _NextSpawn)
  51.         {
  52.             if (estadoAtual == Estado.RANDOM)
  53.             {
  54.                 float pos = Random.Range(40,48);
  55.                 InstanciaTigela(pos);
  56.                 contador += 1;
  57.                 if (contador >= 5)
  58.                 {
  59.                     estadoAtual = SorteiaEstado();
  60.                     contador = 0;
  61.                 }
  62.             }
  63.             if (estadoAtual == Estado.LINHA)
  64.             {
  65.                 float pos = 44;
  66.                 if (contador == 0)
  67.                 {
  68.                     pos = Random.Range(40,48);
  69.                 }
  70.                 InstanciaTigela(pos);
  71.                 contador += 1;
  72.                 if (contador >= 10)
  73.                 {
  74.                     estadoAtual = SorteiaEstado();
  75.                     contador = 0;
  76.                 }
  77.             }
  78.             if (estadoAtual == Estado.DIAGONAL_LEFT)
  79.             {
  80.                 float pos = 48;
  81.                 InstanciaTigela(pos-1 - contador * 1);
  82.                 contador += 1;
  83.                 if (contador >= 6)
  84.                 {
  85.                     estadoAtual = SorteiaEstado();
  86.                     contador = 0;
  87.                 }
  88.             }
  89.             if (estadoAtual == Estado.DIAGONAL_RIGHT)
  90.             {
  91.                 float pos = 40;
  92.                 InstanciaTigela(pos+1 + contador * 1);
  93.                 contador += 1;
  94.                 if (contador >= 6)
  95.                 {
  96.                     estadoAtual = SorteiaEstado();
  97.                     contador = 0;
  98.                 }
  99.             }
  100.             if (estadoAtual == Estado.NONE)
  101.             {
  102.                 contador += 1;
  103.                 if (contador >= 3)
  104.                 {
  105.                     estadoAtual = SorteiaEstado();
  106.                     if (estadoAtual == Estado.NONE)
  107.                     {
  108.                         while(estadoAtual == Estado.NONE)
  109.                         {
  110.                             estadoAtual = SorteiaEstado();
  111.                         }
  112.                     }
  113.                     contador = 0;
  114.                 }
  115.                 _NextSpawn += Interval;
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment