Advertisement
Guest User

Untitled

a guest
May 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5.  
  6. public class BurstBubble : MonoBehaviour
  7. {
  8.     RandomNumber randomNumber;
  9.     SpawnBalls spawnBalls;
  10.  
  11.     RaycastHit hit;
  12.  
  13.     void Awake ()
  14.     {
  15.         randomNumber = FindObjectOfType<RandomNumber> ();
  16.         spawnBalls = FindObjectOfType<SpawnBalls> ();
  17.     }
  18.  
  19.     void Update ()
  20.     {
  21.         if (Input.GetMouseButtonDown (0)) {
  22.    
  23.             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  24.    
  25.             if (Physics.Raycast (ray, out hit)) { //correct answer
  26.                 if (hit.collider.name == RandomNumber.result.ToString ()) {
  27.                     GameObject correctBubble = hit.collider.gameObject;
  28.                     PlayerData.playerData.userList.Insert (0, new playerData (PlayerData.currentUser, PlayerData.PlayerPoints++));
  29.                     Destroy (correctBubble);//DODAC ANIMACJE ZNISZCZENIA ODPOWIEDNIEJ BAŃKI
  30.                     StartCoroutine (Destroy ());
  31.                 } else {
  32.                     GameObject wrongBubble = hit.collider.gameObject;
  33.                     randomNumber.Results.Remove (int.Parse (wrongBubble.gameObject.name)); // remove number from List
  34.                     Destroy (wrongBubble);
  35.                 }
  36.             }
  37.         }
  38.     }
  39.  
  40.     IEnumerator Destroy ()
  41.     {
  42.         for (int i = 0; i < spawnBalls.parentObject.transform.childCount; i++) {
  43.             Destroy (spawnBalls.parentObject.transform.GetChild (i).gameObject, 1.3f);
  44.             //Debug.Log (spawnBalls.parentObject.transform.GetChild (i));
  45.             yield return new WaitForSeconds (.3f);
  46.         }
  47.         yield return new WaitForSeconds (2f);
  48.         randomNumber.MathBubbles ();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement