Accessing string from other script
Hi guys, I have a flappy bird like game , in which i want to put an online leaderbord(with dreamlo),But i have the score code in one script and username code in another.So, in order to add the highscores to dreamlo online leaderbord, need to acces the username string.( i'm new with unity/c# sorry if it sounds very stupid) From the tutorial,I need to put - Highscores.AddNewHighscore(username, score); right under the game code(if it was in one place). Tried username = GetComponent(); but i get - Cannot implicitly convert type "InputName" to "string". Sorry again, Thank you !
can you link your scripts in here so we can give you direct help?
Answer by LiloE · Mar 30, 2017 at 04:12 PM
Inside the InputName class expose a public string that will hold the user name, like so:
class InputName : MonoBehaviour {
//.... rest of the code
public string UserName;
//.... rest of the code
}
And inside your HigeScores class add this code:
class HigeScores: MonoBehaviour {
//.... rest of the code
// inside a function...
string name = GetComponent<InputName>().UserName;
//.... rest of the code
}
Your answer
Follow this Question
Related Questions
How to display random questions without repeating the previous? 2 Answers
arrow from text to object - complete beginner 0 Answers
Issues using two scripts. 1 Answer
How can i place subjects in different positions? 0 Answers
How do you make your player jump in the Roll-a-Ball tutorial series? 0 Answers