Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Spawner : MonoBehaviour {
- public GameObject PilePrefab;
- public int pileLife;
- public LampLife lpLife;
- private GameObject newPile;
- public bool alreadySpawned;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- alreadySpawned = alreadySpawn();
- if((int)lpLife.powerLife >= 1){
- if(lpLife.powerLife <= 5 && !alreadySpawned){
- InstantiatePile(true);
- }
- else if(lpLife.powerLife >= 5 && alreadySpawned){
- InstantiatePile(false);
- }
- }
- else {
- }
- }
- void Awake (){
- }
- void InstantiatePile(bool instanceIt){
- if(instanceIt){
- RectTransform panel = this.GetComponent<RectTransform>();
- Vector2 position = new Vector2(Random.Range(0, panel.rect.width), Random.Range(0,panel.rect.height));
- GameObject newPile = Instantiate<GameObject>(PilePrefab, position, Quaternion.identity);
- newPile.transform.SetParent(this.transform);
- }
- else if(!instanceIt){
- DestroyObject(GetComponentInChildren<OnClickGetPower>().gameObject);
- }
- if(alreadySpawned && Time.time == 2){
- DestroyObject(GetComponentInChildren<OnClickGetPower>().gameObject);
- }
- }
- bool alreadySpawn(){
- if(this.GetComponentInChildren<OnClickGetPower>() == true){
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment