protected void init() { shield_indicator_script = GameObject.Find("Shield Indicator").GetComponent <ShieldBehaviour>(); health_slider = GameObject.Find("Health Slider"); health_color = GameObject.Find("Fill"); damage_slider = GameObject.Find("Damage Slider"); damage_bar = GameObject.Find("Damage Amount"); fade_out = GameObject.Find("Fade Out"); cooldown_slider = GameObject.Find("Cooldown Slider"); cooldown_bar = GameObject.Find("Cooldown Amount"); my_rigidBody = GetComponent <Rigidbody2D>(); torch_object = transform.Find("Torch").gameObject; permanent_torch_object = transform.Find("Permanent Torch").gameObject; sprite_renderer = GetComponent <SpriteRenderer>(); residual_particles = gameObject.GetComponent <ParticleSystem>(); blast_wave_particles = permanent_torch_object.GetComponent <ParticleSystem>(); audio_source = gameObject.GetComponent <AudioSource>(); dark_sfx = new AudioClip[3] { dark_sfx_1, dark_sfx_2, dark_sfx_3 }; damage_sfx = new AudioClip[3] { damage_sfx_1, damage_sfx_2, damage_sfx_3 }; damage_countdown = 0.0f; current_health = Player.player_health; ToggleState(); }
public override void GrantPower() { ShieldBehaviour shield = GetShield(); shield.activateShield(powerDuration); base.GrantPower(); }
public override void Use(Player player) { if (canBeUsed) { if (!isActive) { player.stats.damageAbsorptionActive = true; player.stats.damageAbsorptionAmount = Mathf.CeilToInt(player.stats.healthMax * healthFactor); GameObject shieldGO = (GameObject)Instantiate(prefab, player.centerTransform) as GameObject; shieldGO.transform.localPosition = Vector3.zero + Vector3.up * 0.3f; behaviour = shieldGO.GetComponent <ShieldBehaviour>(); behaviour.Init(player, this); isActive = true; } else { if (behaviour != null) { behaviour.Disable(); } } } }
public override void DenyPower() { ShieldBehaviour shield = GetShield(); shield.deactivateShield(); base.DenyPower(); }
public void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.GetComponent <WallColliderSensor>() != null) { if (this.leaveShieldTimer > 0) { this.leaveShieldTimer = 0; } if (maxBounceCount <= currentBounceCount) { shooterTank.DecreaseCurrentBulletCount(); Destroy(this.gameObject); } Vector3 contactPoint3D = new Vector3(collision.contacts[0].point.x, collision.contacts[0].point.y, 0.0f); Vector3 dir = Vector3.Reflect((contactPoint3D - transform.position).normalized, collision.contacts[0].normal); float angle = 0; if (dir.x == 0) { angle = Mathf.Atan2(-direction.x, direction.y) * Mathf.Rad2Deg + 180 - (2 * Mathf.Atan2(-direction.x, direction.y) * Mathf.Rad2Deg); } else if (dir.y == 0) { angle = Mathf.Atan2(direction.x, -direction.y) * Mathf.Rad2Deg + 180 - (2 * Mathf.Atan2(direction.x, -direction.y) * Mathf.Rad2Deg); } else { angle = Mathf.Atan2(-direction.x, direction.y) * Mathf.Rad2Deg + 180; } var targetRot = Quaternion.AngleAxis(angle, Vector3.forward); transform.rotation = targetRot; currentBounceCount++; } IBulletHittable hitObject = collision.collider.GetComponent <IBulletHittable>(); if (hitObject != null) { ShieldBehaviour myShield = collision.collider.GetComponent <ShieldBehaviour>(); if (myShield != null && myShield.parentTank == shooterTank) { return; } shooterTank.DecreaseCurrentBulletCount(); hitObject.HandleBulletHit(TankDefs.BulletType.Normal); Destroy(this.gameObject); } }
public void InitializeaTank() { dead = false; currentBulletCount = 0; SetBulletType(bulletModifier); if (ownSprite == null) { ownSprite = gameObject.GetComponent <SpriteRenderer>(); if (ownSprite == null) { ownSprite = gameObject.GetComponentInChildren <SpriteRenderer>(); } } if (ownSprite != null) { ownSprite.enabled = true; } if (ownCollider == null) { ownCollider = gameObject.GetComponent <Collider2D>(); if (ownCollider == null) { ownCollider = gameObject.GetComponentInChildren <Collider2D>(); } } if (ownCollider != null) { ownCollider.enabled = true; } if (rig == null) { rig = GetComponent <Rigidbody2D>(); } if (ownShield == null) { ownShield = gameObject.GetComponentInChildren <ShieldBehaviour>(); } if (ownShield != null) { ownShield.TurnOffShield(); shielded = false; } }
public void OnTriggerEnter2D(Collider2D collider) { IBulletHittable hitObject = collider.GetComponent <IBulletHittable>(); if (hitObject != null) { ShieldBehaviour myShield = collider.GetComponent <ShieldBehaviour>(); if (myShield != null && myShield.parentTank == shooterTank && leaveShieldTimer >= 0) { return; } shooterTank.DecreaseCurrentBulletCount(); hitObject.HandleBulletHit(TankDefs.BulletType.Normal); Destroy(this.gameObject); } }
private void SetBulletType(TankDefs.BulletType bulletType) { switch (bulletType) { case TankDefs.BulletType.Normal: shielded = false; if (ownShield == null) { ownShield = gameObject.GetComponentInChildren <ShieldBehaviour>(); } if (ownShield != null) { TurnOffShield(); } this.bulletModifier = TankDefs.BulletType.Normal; this.bulletPrefab = PickupManager.Instance.GetBulletPrefab(this.bulletModifier); this.modifierShots = 0; this.maxBulletCount = 4; this.reloadSpeed = 1; break; case TankDefs.BulletType.LonglivingShot: shielded = false; if (ownShield == null) { ownShield = gameObject.GetComponentInChildren <ShieldBehaviour>(); } if (ownShield != null) { TurnOffShield(); } this.bulletModifier = TankDefs.BulletType.LonglivingShot; this.bulletPrefab = PickupManager.Instance.GetBulletPrefab(this.bulletModifier); this.modifierShots = 4; this.maxBulletCount = 4; this.reloadSpeed = 1; break; case TankDefs.BulletType.Minigun: shielded = false; if (ownShield == null) { ownShield = gameObject.GetComponentInChildren <ShieldBehaviour>(); } if (ownShield != null) { TurnOffShield(); } this.bulletModifier = TankDefs.BulletType.Normal; this.bulletPrefab = PickupManager.Instance.GetBulletPrefab(this.bulletModifier); this.modifierShots = 20; this.maxBulletCount = 20; this.reloadSpeed = 0.05f; break; case TankDefs.BulletType.Shotgun: shielded = false; if (ownShield == null) { ownShield = gameObject.GetComponentInChildren <ShieldBehaviour>(); } if (ownShield != null) { TurnOffShield(); } this.bulletModifier = TankDefs.BulletType.Shotgun; this.bulletPrefab = PickupManager.Instance.GetBulletPrefab(this.bulletModifier); this.modifierShots = 4; this.maxBulletCount = 12; this.reloadSpeed = 1.2f; break; // Special Non-Bullet modifiers case TankDefs.BulletType.Shield: shielded = true; if (ownShield == null) { ownShield = gameObject.GetComponentInChildren <ShieldBehaviour>(); } if (ownShield != null) { TurnOnShield(); } this.bulletModifier = TankDefs.BulletType.Normal; bulletPrefab = PickupManager.Instance.GetBulletPrefab(TankDefs.BulletType.Normal); modifierShots = 0; maxBulletCount = 4; reloadSpeed = 1; break; } }
// Update is called once per frame void Update() { Cooldown -= Time.deltaTime; if (charController.isGrounded) { var emision = RunningParticles.emission; emision.rateOverDistance = 7; } else { var emision = RunningParticles.emission; emision.rateOverDistance = 0; } animatorcheking(); attackActive(); x = Input.GetAxisRaw(axename); isGrounded = ((charController.collisionFlags & CollisionFlags.Below) != 0); if ((Input.GetButtonDown(AttackButton) && canUseSword) && (!IsDefending)) { anim.SetTrigger("Attack"); SonidoEspada.Play(); } //velocidad = charController.velocity; if (x != 0) { isMoving = true; } else { isMoving = false; } anim.SetBool("isMoving", isMoving); anim.SetBool("isFalling", isFalling); anim.SetBool("isGrounded", charController.isGrounded); transform.position = new Vector3(transform.position.x, transform.position.y, 0); if (Input.GetButtonDown(AttackButton)) { if (powerUp) { powerUp.Usar(); } } movimiento = new Vector3(x * speed * 0.1f, movimiento.y - gravityScale * Time.deltaTime, 0); if (PauseMenuManager.IsPaused == false) { if (((((Input.GetButton(ShieldButton) || (Input.GetButton(ShieldButton2))) /*&& (this.tag == "P1") */) && (!IsDefending)) && (Cooldown < 0))) { Instantiate(escudo, this.transform); protect = GetComponentInChildren <ShieldBehaviour>(); CurEscudo = protect.gameObject; IsDefending = true; } else if ((((Input.GetButtonUp(ShieldButton) || (Input.GetButtonUp(ShieldButton2))) /*&& (this.tag == "P1")*/) && (IsDefending))) { Destroy(CurEscudo); Cooldown = Cadencia; IsDefending = false; } else if (CurEscudo.GetComponent <ShieldBehaviour>().destroy) { IsDefending = false; Cooldown = Cadencia; } } //if (((((Input.GetButton(ShieldButton) || (Input.GetButton(ShieldButton2))) && (this.tag == "P2")) && (!IsDefending)) && (Cooldown < 0))) //{ // Instantiate(escudo, this.transform); // protect = GetComponentInChildren<ShieldBehaviour>(); // CurEscudo = protect.gameObject; // IsDefending = true; //} //else if ((((Input.GetButtonUp(ShieldButton) || (Input.GetButtonUp(ShieldButton2))) && (this.tag == "P2")) && (IsDefending))) //{ // Destroy(CurEscudo); // Cooldown = Cadencia; // IsDefending = false; //} //else if (CurEscudo.GetComponent<ShieldBehaviour>().destroy) //{ // IsDefending = false; // Cooldown = Cadencia; //} }
private void Awake() { _shieldBehaviour = GetComponentInChildren <ShieldBehaviour>(); }