Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SetSpawner : MonoBehaviour {
- //Object pools
- //Easy objectpool
- //Normal objectpool
- //Hard objectpool
- public bool canSpawn;
- public Transform spawnTransform;
- private HighScore difficultySetter;
- private SetObjectPools objectPool;
- private float _easyChance;
- private float _normalChance;
- private float _hardChance;
- private float _totalChance;
- // Percentage spawn chance
- private float _easySpawnChance;
- private float _normalSpawnChance;
- private float _hardSpawnChance;
- private float _randomValue;
- private Vector3 _endOfSet;
- private Vector3 spawnPosition;
- void Awake()
- {
- difficultySetter = GameObject.Find("GameController").GetComponent<HighScore>();
- objectPool = GameObject.Find("SetObjectPooler").GetComponent<SetObjectPools>();
- spawnPosition = new Vector3(spawnTransform.position.x, spawnTransform.position.y, spawnTransform.position.z);
- canSpawn = true;
- }
- // Update is called once per frame
- void Update()
- {
- if (_endOfSet.x < spawnPosition.x)
- {
- canSpawn = true;
- Debug.Log(" first if statement, should be true " + canSpawn);
- Debug.Log("_endofSet.x :" + _endOfSet.x + ", spawnPosition.x:" + spawnPosition.x);
- }
- if (canSpawn)
- {
- switch (difficultySetter.currentDifficulty)
- {
- case 0: //easy
- _easyChance = 100;
- _normalChance = 0;
- _hardChance = 0;
- break;
- case 1: // normal
- _easyChance = 100;
- _normalChance = 500;
- _hardChance = 0;
- break;
- case 2: // hard
- _easyChance = 100;
- _normalChance = 500;
- _hardChance = 1500;
- break;
- }
- // Calculate percentages
- _totalChance = _easyChance + _normalChance + _hardChance;
- _easySpawnChance = _easyChance / _totalChance;
- _normalSpawnChance = _normalChance / _totalChance;
- _hardSpawnChance = _hardChance / _totalChance;
- // Spawns the set based on a random value and the spawn percentages.
- // TODO: Break after if statement is done
- _randomValue = Random.value;
- if (_randomValue <= _easySpawnChance)
- {
- objectPool.chosenSets = objectPool.easySets;
- SpawnSet();
- }
- _randomValue -= _easySpawnChance;
- if (_randomValue <= _normalSpawnChance)
- {
- objectPool.chosenSets = objectPool.normalSets;
- SpawnSet();
- }
- _randomValue -= _normalSpawnChance;
- if (_randomValue <= _hardSpawnChance)
- {
- objectPool.chosenSets = objectPool.hardSets;
- SpawnSet();
- }
- }
- }
- void SpawnSet()
- {
- Debug.Log("Spawn Set is just called, canSpawnshould be true, it is: " + canSpawn);
- GameObject set = objectPool.GetPooledSet();
- set.transform.position = spawnPosition;
- //newItem.transform.rotation = transform.rotation;
- set.SetActive(true);
- _endOfSet = set.gameObject.transform.GetChild(0).localPosition;
- canSpawn = false;
- Debug.Log(_endOfSet + " this is the end of the (just spawned) set position...");
- Debug.Log(" Spawn set is doner, canSpawn should be false, it is " + canSpawn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement