Search Unity

C# how can I set the value of a variable in one script component to another?

Discussion in 'Scripting' started by From-Soy-Sauce, Sep 1, 2014.

  1. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Hello, in my game I have multiple characters that each have their own specific script to control them, but they also each have a script of variables that govern the rules of the game and how the characters interact with each other.

    for example: in the script "VarsForAllChars" HP is set to 5 at the start. So how do I make it so that in another script that is attached to the character as a component, lets say "ControlJames" that james is allowed to set the HP value in his VarsForAllChars script at anytime?
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
    Use GetComponent from the "ControlJames" script to get the "VarsForAllChars" component.