// Start is called before the first frame update void Start() { playerModifiers = playerModifiersGameObject.GetComponent <PlayerModifiers>(); foreach (GameObject LaserGun in laserGuns) { playerLaserGuns.Add(LaserGun.GetComponent <LaserGun>()); laserGunTemplate = LaserGun.GetComponent <LaserGun>(); } playerFirestormX = firestormX.GetComponent <FirestormX>(); playerRenderer = GetComponent <SpriteRenderer>(); energyStatusBar = EnergyBar.GetComponent <UIStatusBar>(); firestormXStatusBar = FirestormXBar.GetComponent <UIStatusBar>(); playerStatus = playerStatusGameObject.GetComponent <PlayerStatus>(); upgradesDisplay = upgradesIcons.GetComponent <UIDisplayUpgrades>(); deathSound = deathSoundObject.GetComponent <AudioSource>(); newPositionDirection = 1; duplicateCount = 1; spawnCount = 0; constantNewPositionDifference = playerModifiers.newPositionDifference; pointsDisplay = pointsUI.GetComponent <UIDisplayNumbers>(); PlayerCollision.onEnemyHit += substractEnergy; PlayerCollision.onEnemyHit += RemoveUpgrades; PlayerCollision.onEnergyCollected = RecoverEnergy; PlayerCollision.onRocketCollected = addCannon; GameManager.onRoundEnd += disableUI; GameManager.onRoundEnd += disableCollision; GameManager.onRoundEnd += disableGuns; }
private void addCannon() { if (playerLaserGuns.Count < playerModifiers.maxCannons) { for (int i = 0; i < 2; i++) { LaserGun laserGunInstance = Instantiate(laserGunTemplate); laserGunInstance.transform.SetParent(gameObject.transform); laserGunInstance.transform.localPosition = Vector3.zero; laserGunInstance.GetComponent <LaserGun>().isMainGun = false; spawnCount++; newPositionDirection = newPositionDirection * -1; laserGunInstance.transform.localPosition = laserGunInstance.transform.localPosition + (new Vector3(constantNewPositionDifference, 0, 0) * newPositionDirection); // direction 1 or -1 playerLaserGuns.Add(laserGunInstance); if (isSpawnCountPair()) { duplicateCount++; constantNewPositionDifference = playerModifiers.newPositionDifference * duplicateCount; spawnCount = 0; } } upgradesDisplay.addUpgradeIcon(); } }