Search Unity

Get int from an specific child and set it to a variable in the parent.

Discussion in 'Scripting' started by nerocraftmc4, Jun 19, 2018.

  1. nerocraftmc4

    nerocraftmc4

    Joined:
    Jun 19, 2018
    Posts:
    1
    I do really need help with this. I've been trying to solve the problem but i don't know what to do! This might seem dumb or stupid but i'm realatively new to Unity.

    -How can I get an integer from an specific child? I'm trying to figure it out but I can't.

    unitythread.PNG
    unitythread2.PNG

    Here I want to get different integers: Stamina required, strength required, attack time, DMG... and more.
    And I want to make the variables of the Swoosh Effect, for example, make my DMG (depending on the DMG of the ACTIVE WEAPON in Weapon) equal to the Damage To Give in here (in every frame):

    unitythread3.PNG

    Here is the code of my Base Weapon Script and my Hurt Enemy Script.

    Code (CSharp):
    1. public class BaseWeapon : BaseStatItem { //<- BaseItem
    2.  
    3.     public enum WeaponTypes
    4.     {
    5.         SWORD,
    6.         DAGGER,
    7.         BOW,
    8.         CROSSBOW,
    9.         STAFF
    10.     }
    11.  
    12.     public WeaponTypes weaponType;
    13.     public int spellEffectID;
    14.     public int DMG, weight, staminiaSpent;
    15.     public float attackTime;
    16.     public bool isMagic;
    17.  
    18.     public WeaponTypes WeaponType
    19.     {
    20.         get { return weaponType; }
    21.         set { weaponType = value; }
    22.     }
    23.  
    24.     public int SpellEffectID
    25.     {
    26.         get { return spellEffectID; }
    27.         set { spellEffectID = value; }
    28.     }
    29. }

    Code (CSharp):
    1. public class HurtEnemy : MonoBehaviour {
    2.  
    3.     [SerializeField]
    4.     public GameObject parent;
    5.     public GameObject DMGBurst;
    6.     public Transform HitPoint;
    7.     public GameObject DMGNumber;
    8.     public Transform activeSword;
    9.     public int damageToGive;
    10.  
    11. private void OnTriggerEnter2D(Collider2D collision)
    12.     {
    13.         //GameObject damageOfTheSword = GameObject.Find("Damager");
    14.         if (collision.gameObject.tag == "Enemy")
    15.         {
    16.             //Destroy(collision.gameObject);
    17.             collision.gameObject.GetComponent<EnemyHealthManager>().HurtEnemy(damageToGive);
    18.             Instantiate(DMGBurst, HitPoint.position, HitPoint.rotation);
    19.             var clone = (GameObject) Instantiate(DMGNumber, HitPoint.position, Quaternion.Euler(Vector3.zero));
    20.             clone.GetComponent<FloatingNumbers>().damageNumber = damageToGive;
    21.         }
    22.     }

    If you could help me I'd really appreciate it! If there's any doubt or anything that's not clear in the thread, just ask me.