Search Unity

[Solved]I need some help with GetComponent taking damage interface

Discussion in 'Scripting' started by Pixitales, Jun 8, 2019.

  1. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    227
    It looks like its working but, my player isn't taking any damage at all. It does display zero. Am I missing something? I wrote 10 damage on the inspector.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public interface ITakeDamageInterface
    6. {
    7.     void TakeDamage(int damageAmount);
    8. }
    Code (CSharp):
    1. public class Player : Character, ITakeDamageInterface
    2.  
    3.     public void TakeDamage(int damageAmount)
    4.     {
    5.         isEnemyKnockBack = true;
    6.  
    7.         health.MyCurrentValue -= DamageToGive;
    8.  
    9.         CombatTextManager.MyInstance.CreateText(transform.position, DamageToGive.ToString(), SCTTYPE.DAMAGE, true);
    10.  
    11.         StartCoroutine("DamageFlash");
    12.     }
    Code (CSharp):
    1. public class Zombie : NPC, ITakeDamageInterface
    2.  
    3.     public void TakeDamage(int damageAmount)
    4.     {
    5.         health.MyCurrentValue -= DamageToGive;
    6.  
    7.         CombatTextManager.MyInstance.CreateText(transform.position, DamageToGive.ToString(), SCTTYPE.DAMAGE, true);
    8.  
    9.         //Blood Splash
    10.         Instantiate(bloodSplash, transform.position, Quaternion.identity);
    11.  
    12.         StartCoroutine("DamageFlash");
    13.  
    14.         if (IsAlive)
    15.         {
    16.             Select(); //Show health bar
    17.         }
    18.     }
    Enemy Attack state
    Code (CSharp):
    1. public class AttackState : IState
    2.  
    3. if (parent.MyTarget != null)
    4.         {
    5.             //Attack player
    6.             //parent.MyTarget.GetComponent<Player>().HurtPlayer(parent.DamageToGive);
    7.  
    8.             ITakeDamageInterface script = parent.MyTarget.GetComponent<ITakeDamageInterface>();
    9.             script.TakeDamage(parent.DamageToGive);
    10.  
    11.         }
     
  2. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    227
    oh nevermind I solved it, theres a typo on the take damage.