Search Unity

Armour

Discussion in 'Scripting' started by The3DKnight, Feb 7, 2013.

  1. The3DKnight

    The3DKnight

    Joined:
    Feb 8, 2011
    Posts:
    240
    Hi again .
    So armor thing , problem.I have health script which contains (health and armour variables).So i wanted like when damage is taken
    if armour <0 {health -=50}.And if if armour >0 {armour -= 50}.
    But how can i do that with from other script
    Here's what i have

    Pick up and Mine damage
    Code (csharp):
    1. var script : Health;
    2.  
    3. function OnTriggerEnter(hit : Collider)
    4.     {  
    5.         if(hit.gameObject.tag == "HealthUP")
    6.         {  
    7.         script = GetComponent("Health");
    8.         script.healt += 55;
    9.             Debug.Log("You picked up the key!");
    10.             Destroy(hit.gameObject);
    11.             }
    12.         if(hit.gameObject.tag == "ArmourUP")
    13.         {  
    14.         script = GetComponent("Health");
    15.        
    16.         script.if(armor<0)
    17.         {
    18.         healt -=50;
    19.         }
    20.         script.if(armor>0)
    21.         {
    22.         armor -=50;
    23.         }
    24.             Debug.Log("You picked up the key!");
    25.             Destroy(hit.gameObject);
    26.            
    27.            
    28.            
    29. }
    30. }
    how can i get it to decrease value from Health script.I get some error with
    Any help or tips.

    -3DK
     
  2. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    'if' is not a component from the script Health.
    You probably want to do something like this(if armor health are variables from the script Health):
    Code (csharp):
    1.  
    2.  
    3. if(script.armor <= 0)
    4. {
    5.     script.health -= 50;
    6. }
    7. else if(script.armor > 0)
    8. {
    9.     script.armor -= 50;
    10. }
    11.  
     
  3. The3DKnight

    The3DKnight

    Joined:
    Feb 8, 2011
    Posts:
    240
    Thank you Falin this is what i needed.
     
  4. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    No Problem, glad that I was able to help. :)