- Home /
I have a little problem getting a component from another script
Hi I am currently making a score system for a game. I have 2 scripts: Movement & Score. The Movement contains a public variable public int score;
I want to get that score into my score script, but it can't find the score:
public class Score : MonoBehaviour {
public int finalScore = 1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
finalScore = GameObject.Find("Pacman").GetComponent<Movement>.;
guiText.text = "Score " + finalScore;
}
}
I get this error: Assets/Scriptes/Score.cs(14,48): error CS0119: Expression denotes a method group', where a
variable', value' or
type' was expected
Answer by MikeNewall · Apr 29, 2014 at 12:23 PM
You're missing parenthesis at the end of the get component method, and after the . you should have the name of the variable you're looking for
finalScore = GameObject.Find("Pacman").GetComponent<Movement>().score;
Your answer
Follow this Question
Related Questions
how to access a float from one script in other script in different objects 3 Answers
Object reference not set to an instance of an object 3 Answers
Find + GetComponent not working as expected 0 Answers
Limiting respawns on scene 1 Answer
Creating a single-line function for GameObject.Find and GetComponent (for multiple components) 3 Answers