Search Unity

my SendMessage isnt working, i need help

Discussion in 'Scripting' started by dovahkiin009087, Nov 18, 2014.

  1. dovahkiin009087

    dovahkiin009087

    Joined:
    Nov 18, 2014
    Posts:
    10
    #pragma strict
    var playerDistance : int;
    var player : GameObject;
    var attacking : boolean;
    var TakeDammage : boolean;
    function Start ()
    {
    player = GameObject.Find("Player");
    attacking = false;
    }
    function Update ()
    {
    playerDistance = Vector3.Distance(player.transform.position, transform.position);
    if(playerDistance <=2)
    {
    if(!attacking)
    {
    Invoke("ApplyDammage", 3);
    attacking = true;
    }
    }
    }
    function ApplyDammage()
    {
    player.SendMessage("SubtractHealth");
    attacking = false;

    }
    function OnTriggerEnter(other : Collider){
    if(other.tag == "Player"){
    TakeDammage = true;
    }
    }
    function OnTriggerExit(other : Collider){
    if(other.tag == "Player"){
    TakeDammage = false;
    }
    }
    this is my script but it doesnt apply damage to the player, how do i fix it, need help asap
     
  2. dovahkiin009087

    dovahkiin009087

    Joined:
    Nov 18, 2014
    Posts:
    10
    function SubractHealth()
    {
    playerHealth--;
    }
    this is the subtract health function
     
  3. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Check the spelling you have. In your second post you're missing a t from the function name.
     
    dovahkiin009087 likes this.
  4. dovahkiin009087

    dovahkiin009087

    Joined:
    Nov 18, 2014
    Posts:
    10
    okay i have another question, if i want my health to decrease faster, how should i change the subtract health function, or the first script, to make that happen?
    and thank you very much for answering
     
  5. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Either approach works. I don't think there is a right or wrong way.
     
  6. dovahkiin009087

    dovahkiin009087

    Joined:
    Nov 18, 2014
    Posts:
    10
    how do i manipulate the script to do that?