private void SpawnBrick(Brick brickData) { Vector3 pos = new Vector3(brickData.x * 16, brickData.y * -8); GameObject brick = Instantiate(brickPrefab, Vector3.zero, Quaternion.identity); brick.transform.parent = this.gameObject.transform; brick.transform.localPosition = pos; Color color; if (ColorUtility.TryParseHtmlString(brickData.color, out color)) { brick.GetComponent <SpriteRenderer>().color = color; BrickController controller = brick.GetComponent <BrickController>(); controller.SetGameController(_gameController); controller.SetHitPoint(brickData.hitPoints); if (brickData.powerUp.name != null) { PowerUpObject pu = powerupMap[brickData.powerUp.name]; if (pu != null) { pu.duration = brickData.powerUp.duration; controller.powerUp = pu; } } } }
public void reset() { // Remove handheled powerup handheldPowerUp.powerUp = null; uiManager.resetPowerUp(playerName); // Remove all actual bonus and malus for (int i = 0; i < activeBonus.Count; i++) { PowerUpObject bonus = activeBonus[i]; // Remove bonus effect icon uiManager.resetPowerUpEffect(playerName, "bonus"); // Deactivate bonus effect and remove it from the list bonus.powerUp.deactivateBonus(player); activeBonus.Remove(bonus); } for (int i = 0; i < activeMalus.Count; i++) { PowerUpObject malus = activeMalus[i]; // Remove malus effect icon uiManager.resetPowerUpEffect(playerName, "malus"); // Deactivate malus effect and remove it from the list malus.powerUp.deactivateMalus(player); activeMalus.Remove(malus); } }
public bool TryEquipPowerUp(PowerUpObject powerUpObject) { this.powerUp = powerUpObject.powerUp; powerCountInInventory++; PowerUpSpawner.isAlreadyPickUpList[powerUpObject.id] = true; Destroy(powerUpObject.gameObject); return(true); }
void Start() { handheldPowerUp = new PowerUpObject(null); controllerIndex = GetComponent <PlayerBehavior>().ControllerIndex; player = GetComponent <PlayerBehavior>(); opponent = findOpponent(); playerName = transform.name.Split('_')[1]; uiManager = GameObject.Find("GameScreenUI").GetComponent <UIManager>(); }
public void DropPowerUp(Vector3 pos, Vector3 baseVelocity) { GameObject gameObject = Instantiate(Prefab, pos + Vector3.up, Quaternion.identity) as GameObject; PowerUpObject obj = gameObject.GetComponent <PowerUpObject>(); obj.Construct(this); Rigidbody2D rigid = gameObject.GetComponent <Rigidbody2D>(); rigid.velocity = new Vector2( baseVelocity.x + (baseVelocity.x < 1f ? 0f : Mathf.Sign(baseVelocity.x) * 1.1f), baseVelocity.y + 5f ); }
void PickUp() { Collider2D coll = Physics2D.OverlapBox(transform.position, new Vector2(2f, 2f), 0f, 1 << LayerMask.NameToLayer("PowerUp")); if (coll) { PowerUpObject pickup = coll.GetComponent <PowerUpObject>(); if (pickup) { playerSound.PlayPickupPowerUp(); PickUpPower(pickup.GetPowerUp(this.gameObject)); } } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "MainCamera") { // collision is with the player. // get the player interface DronePlayer player = other.GetComponent(typeof(DronePlayer)) as DronePlayer; if (player != null) { PowerUpObject obj = (this.gameObject.GetComponent(typeof(PowerUpObject)) as PowerUpObject); if (obj != null) { obj.performPowerupOnPlayer(player); } } Destroy(gameObject); } }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "player") { // collision is with the player. // get the player interface DronePlayer player = collision.gameObject.GetComponent(typeof(DronePlayer)) as DronePlayer; if (player != null) { PowerUpObject obj = (this.gameObject.GetComponent(typeof(PowerUpObject)) as PowerUpObject); if (obj != null) { obj.performPowerupOnPlayer(player); } } Destroy(gameObject); } }
public ActivePowerUp(PowerUpObject powerUp) { this.powerUp = powerUp; this.timer = powerUp.duration; }
public void ActivatePowerUp(PowerUpObject powerUp) { activePowerupList.Add(new ActivePowerUp(powerUp)); powerUp.Apply(this); }
public void SetPowerUp(PowerUpObject pu) { this.powerUp = pu; this.gameObject.name = pu.name; _renderer.color = pu.color; }
void Update() { if (handheldPowerUp.powerUp != null) { if (Input.GetButton("Bonus_" + controllerIndex)) { activateBonus(); } if (Input.GetButton("Malus_" + controllerIndex)) { activateMalus(); } } for (int i = 0; i < activeBonus.Count; i++) { PowerUpObject bonus = activeBonus[i]; if (bonus.startTime == 0) { // Set active bonus powerup icon uiManager.updatePowerUpEffect(playerName, "bonus", bonus.powerUp.bonusIcon); // Activate bonus and calculate end time bonus.powerUp.activateBonus(GetComponent <PlayerBehavior>()); bonus.setStartTime(Time.time); bonus.setEndTime(Time.time + bonus.powerUp.duration); } if (bonus.endTime <= Time.time) { // Remove bonus effect icon uiManager.resetPowerUpEffect(playerName, "bonus"); // Deactivate bonus effect and remove it from the list bonus.powerUp.deactivateBonus(player); activeBonus.Remove(bonus); } } for (int i = 0; i < activeMalus.Count; i++) { PowerUpObject malus = activeMalus[i]; if (malus.startTime == 0.0f) { // Set active malus powerup icon uiManager.updatePowerUpEffect(playerName, "malus", malus.powerUp.malusIcon); // Activate malus and calculate end time malus.powerUp.activateMalus(GetComponent <PlayerBehavior>()); malus.setStartTime(Time.time); malus.setEndTime(Time.time + malus.powerUp.duration); } if (malus.endTime <= Time.time) { // Remove malus effect icon uiManager.resetPowerUpEffect(playerName, "malus"); // Deactivate malus effect and remove it from the list malus.powerUp.deactivateMalus(player); activeMalus.Remove(malus); } } }