- Home /
 
 
               Question by 
               cunibon · Oct 15, 2020 at 08:51 AM · 
                c#variablereferenceautomatically  
              
 
              use string to search in script
Hey i want to use a string to search for a variable in another script like you can see in the code but unity wont let me do that. Is this even possible it would just save me a bit of work but i wanted to automate as much as possible.
     public string ItemName = "Axe";
 
   //Savesystem
     GameData data = SaveSystem.LoadPlayer();
     Item = data. + ItemName;
 
              
               Comment
              
 
               
              Answer by hendryshaikh2004 · Oct 15, 2020 at 07:08 PM
you can do it by encapsulation you cannot inherit string and variables you can do it like this If it helps please give alike means alot
On Script A
public string ReturnGrenade() { return noOfGrenade; //it will return String }
on Script B
 [SerializeField] ScriptA scriptA; //intialization of ScriptA
     string nade = scriptA.ReturnGrenade(); //Searches and return a variable for Script A
 
 
              Your answer