An error occurred while loading the file. Please try again.
-
geraldabrhm authored7e7006b1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PetBuff : MonoBehaviour
{
public float timeBetweenHeal = 10f;
public int healQuantity = 20;
public int atkMultQuantity = 2;
public PetTypeEnum petType;
Animator anim;
GameObject player;
PlayerHealth playerHealth;
DefaultShooting playerShooting;
bool playerInRange;
float timer;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player");
playerHealth = player.GetComponent <PlayerHealth> ();
playerShooting = player.GetComponentInChildren<DefaultShooting>();
anim = GetComponent <Animator> ();
}
void Start ()
{
if(petType == PetTypeEnum.Aura)
{
Aura();
}
}
void OnTriggerEnter (Collider other)
{
// If the entering collider is the player...
if(other.gameObject == player && other.isTrigger == false)
{
// ... the player is in range.
playerInRange = true;
}
}
void OnTriggerExit (Collider other)
{
// If the exiting collider is the player...
if(other.gameObject == player)
{
// ... the player is no longer in range.
playerInRange = false;
}
}
void Update ()
{
timer += Time.deltaTime;
// If the timer exceeds the time between attacks, the player is in range and this enemy is alive...
if(timer >= timeBetweenHeal && playerInRange)
{
// ... heal.
if(petType == PetTypeEnum.Healer)
{
Heal();
if (playerHealth.currentHealth > 0)
{
// ... tell the animator to make groot have a healing animation
anim.SetTrigger ("HealPlayer");
}
}
}
}
void Heal()
{
timer = 0f;
// If the player health is not full...
if (playerHealth.currentHealth < 100)
{
// ... heal the player.
playerHealth.GetHeal(healQuantity);
}
// Debug.Log($"Do healing, now player health: {playerHealth.currentHealth}"); // ! Debug
}
void Aura()
{
playerShooting.damagePerShot *= atkMultQuantity;
}
}