Nekrosincoding

Spawner

Jun 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawner : MonoBehaviour {
  6.  
  7. public GameObject PilePrefab;
  8. public int pileLife;
  9. public LampLife lpLife;
  10. private GameObject newPile;
  11. public bool alreadySpawned;
  12.  
  13. // Use this for initialization
  14. void Start () {
  15.  
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update () {
  20. alreadySpawned = alreadySpawn();
  21. if((int)lpLife.powerLife >= 1){
  22. if(lpLife.powerLife <= 5 && !alreadySpawned){
  23. InstantiatePile(true);
  24. }
  25. else if(lpLife.powerLife >= 5 && alreadySpawned){
  26. InstantiatePile(false);
  27. }
  28. }
  29. else {
  30.  
  31. }
  32. }
  33. void Awake (){
  34. }
  35.  
  36. void InstantiatePile(bool instanceIt){
  37. if(instanceIt){
  38. RectTransform panel = this.GetComponent<RectTransform>();
  39. Vector2 position = new Vector2(Random.Range(0, panel.rect.width), Random.Range(0,panel.rect.height));
  40. GameObject newPile = Instantiate<GameObject>(PilePrefab, position, Quaternion.identity);
  41. newPile.transform.SetParent(this.transform);
  42. }
  43. else if(!instanceIt){
  44. DestroyObject(GetComponentInChildren<OnClickGetPower>().gameObject);
  45. }
  46.  
  47. if(alreadySpawned && Time.time == 2){
  48. DestroyObject(GetComponentInChildren<OnClickGetPower>().gameObject);
  49. }
  50. }
  51.  
  52. bool alreadySpawn(){
  53. if(this.GetComponentInChildren<OnClickGetPower>() == true){
  54. return true;
  55. }
  56. return false;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment