protected void Awake() { health = maxHealth; Stamina = maxStamina; currentState = State.Patrol; myTransform = GetComponent <Transform>(); bodyCollider = GetComponent <Collider2D>(); rigidBody = GetComponent <Rigidbody2D>(); sprite = GetComponent <SpriteRenderer>(); startPos = myTransform.position; playerAttributes = GameObject.FindWithTag("Player").GetComponent <PlayerAttributes>(); statusBarTransform.TryGetComponent(out StatusBar _bar); statusBar = _bar; statusBar.maxHealth = maxHealth; statusBar.HealthChange(health); foreach (Transform t in transform) { if (t.tag == "Hook Target") { myHookTarget = t; } } if (bodyCollider is PolygonCollider2D) { PolygonCollider2D _col = (PolygonCollider2D)bodyCollider; foreach (Vector2 point in _col.points) { colliderWidth = point.x > colliderWidth ? point.x : colliderWidth; } } }
void Start() { anim = GetComponent <Animator>(); movement = GetComponent <PlayerMovement>(); rigidBody = GetComponent <Rigidbody2D>(); effectsController = GetComponent <PlayerEffectsController>(); statusBar = statusBarTransform.GetComponent <StatusBar>(); speedDivisor = defSpeedDivisor; //attackSpeed = defAttackSpeed; AnimSpeed = defAnimSpeed; health = maxHealth; curHealingPotionCount = healingPotionCount; staminaFloat = stamina = maxStamina; statusBar.maxHealth = maxHealth; statusBar.HealthChange(health); statusBar.maxStamina = maxStamina; statusBar.StaminaChange(stamina); healingPotion.SetItemCount(curHealingPotionCount); }
/// <summary> /// Just damage /// </summary> public int TakeDamage(int damage, HurtType hurtType, Element element) { if (isInvulnerable) { return(0); } if (damage > 0 || element.value > 0) { health -= damage + element.value; timeOfLastTakenDamage = Time.time; statusBar.HealthChange(health); //Decrease energy //float _percentageConversionToEnergy = .05f; //Energy -= damage * _percentageConversionToEnergy; DamageText(damage, element); } if (health <= 0) { movement.isDead = true; isInvulnerable = true; movement.bodyCollider.sharedMaterial = null; //Delete collider material for turn on friction AudioManager.PlayDeathAudio(); return(damage + element.value); } else { AudioManager.PlayHurtAudio(); } //Camera shake float _maxAmplitude = 8f; float _shakeAmplitude = (damage + element.value) / (float)maxHealth * _maxAmplitude; cameraShake.Shake(_shakeAmplitude, 1f, .25f); return(damage + element.value); }