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. Dismiss Notice

Having problems getting variable to work with other scripts

Discussion in 'Scripting' started by Bulslayer90, Feb 12, 2013.

  1. Bulslayer90

    Bulslayer90

    Joined:
    Dec 24, 2012
    Posts:
    40
    Im trying to get my player health varaible or Phealth as i named it to be refferenced to by my enemy AI scripts and no matter what i do i keep getting stupid errors saying either Ambigous reff or "Phealth is not a member of Object"

    Code (csharp):
    1. ph = player.GetComponent(Kasshud.Phealth);
    this is what i have in the update function so far for my enemyAI and with MonoDevelop tool acting up and randomly closing on me and not always recognizing changes in scripts nor letting me even open them properley by clicking on them i cant figure out if im doing something wrong or its MonoDevelop
     
    Last edited: Feb 12, 2013
  2. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    I think what you want is

    ph = player.GetComponent(Kasshud).Phealth;

    presuming that" Kasshud' is the name of your script, Phealth is a variable within it and player is a gameobject with the scritpt "Kasshud" attached to it.
     
  3. Bulslayer90

    Bulslayer90

    Joined:
    Dec 24, 2012
    Posts:
    40
    umm ok so im probbably going to sound really retarded right now so i apologize in advance, i tried that before and it brought up an error but the script name was "kass hud" not "kasshud". im guessing what was throwing the error was the fact that i had a space in the script name because i tried that again now that you said to and it frickin worked.