private void Awake() { if (Pool != null && Pool != this) { Debug.LogWarning("La pool de atomos ya existe! Eliminando este objeto...", gameObject); Destroy(gameObject); } Pool = this; atoms = new List <GameObject>(initialAtoms); for (int i = 0; i < initialAtoms; i++) { GameObject atom = Instantiate(atomPrefab); atom.SetActive(false); atoms.Add(atom); } antiAtoms = new List <GameObject>(); for (int i = 0; i < initialAnti; i++) { GameObject anti = Instantiate(antiAtomPrefab); anti.SetActive(false); antiAtoms.Add(anti); } }
public static AtomPool GetInstance() { if (instance == null) { instance = new AtomPool(); } return(instance); }
void Start() { registeredAtomCreateCommands.Add(new EnemyAtomCreateCommand(AtomPool.GetInstance())); registeredAtomCreateCommands.Add(new FriendlyAtomCreateCommand(AtomPool.GetInstance())); Collider leftCollider = leftWall.GetComponent <Collider>(); Collider rightCollider = rightWall.GetComponent <Collider>(); xLeftOfPlayfield = leftWall.transform.position.x + leftCollider.bounds.extents.x + horizontalSafetyMargin; xRightOfPlayfield = rightWall.transform.position.x - rightCollider.bounds.extents.x - horizontalSafetyMargin; }
void Update() { if (hasGameEnded && Input.GetKeyUp(KeyCode.R)) { AtomPool.ResetAtomPool(); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } if (Input.GetKeyUp(KeyCode.Escape)) { Application.Quit(); } }
void OnCollisionEnter(Collision collision) { if (isDestroyed) { return; } //If the atom we collided with is friendly, we do our stuff if (collision.gameObject.GetComponentInChildren <EnemyController>() == null) { isDestroyed = true; foreach (Docker docker in dockers) { docker.OnHitEnemy(); } destroyAnimator.ResetTrigger("Reset"); destroyAnimator.SetTrigger("Destroy"); const int secondsTillDestruction = 1; AtomPool.GetInstance().DestroyEnemyAtom(transform.parent.gameObject, secondsTillDestruction); } }
public EnemyAtomCreateCommand(AtomPool atomPool) : base(atomPool) { }
public AtomCreateCommand(AtomPool atomPool) { this.atomPool = atomPool; }
public static void ResetAtomPool() { instance = null; }
public FriendlyAtomCreateCommand(AtomPool atomPool) : base(atomPool) { }