Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

    Unity Technologies

    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

    Unity Technologies

    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?