Search Unity

Getting a string from another script

Discussion in 'Getting Started' started by Bendillon, May 9, 2019.

  1. Bendillon

    Bendillon

    Joined:
    May 2, 2019
    Posts:
    1
    Hey There. I've just started using Unity and are making a game. I have a thing(variable I think its called) in one script saying " teamOneName = teamOne.text;". I need to use teamOne on another script and have no idea on how I do that. Any help is welcome.

    Thanks
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You need to get a reference to this other component, and then you access the variable directly if you set is as public, or return in through a public method (function). There are a variety of ways to get the reference to the component. You can set via the inspector, you can use GetComponent, you can find the GameObject it is attached to or have it supplied through a collision. Read through the manual or search for topics here on getting references to objects and components.