Search Unity

How to take away from a variable? JAVA SCRIPT

Discussion in 'Scripting' started by Smotteh, May 28, 2015.

  1. Smotteh

    Smotteh

    Joined:
    May 28, 2015
    Posts:
    22
    Could someone tell me whats wrong with this?

    Heres My Errors
    Assets/Destroy.js(12,15): BCE0034: Expressions in statements must only be executed for their side-effects.
    Assets/Destroy.js(15,8): BCE0046: 'is' can't be used with a value type ('int')
    Heres My Code...How do i take away 5 from health everytime i click fire1?

    #pragma strict

    public var other : GameObject;
    var Damage = 5;
    var Health = 20;

    function Update ()
    {
    if(Input.GetButtonDown("Fire1"))
    {
    Health - Damage;
    }

    if(Health === 0)
    {
    Destroy(other);
    }

    }
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Try "Health = Health - Damage" instead.

    And there should be only two equals signs for "is equal to" - but you should do "if (Health <= 0)" on the lower part.
     
  3. Smotteh

    Smotteh

    Joined:
    May 28, 2015
    Posts:
    22
    Thanks so much! Works........Ive Been trying to learn code forever, this site is perfect !
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    No problem, good luck!