- Home /
When attempting to call a method from within another script I get this error.
I am attempting to call a function (GameOver) from the script HighScores3, in another script (scoreZone).
This is the line of code I have which seems not to be working
HighScores3 scriptref = reference2.GetComponent < HighScores3>().GameOver;
I get an error which say 'cannot convert method group 'GameOver' to non-delegate type 'HighScores3'. Did you intend to invoke the method?.
Not quite sure what Ive done wrong as I thought that was how to call a method from another script.
Thanks in advance for any help that can be offered.
Jack Perry
Answer by Ado · Mar 10, 2014 at 08:03 PM
First you need to assign your script to a variable so you can access its functions. (Do this in Awake)
HighScores3 scriptref = reference2.GetComponent< HighScores3 >()
then you can call the functions through your variable when needed.
scriptref.GameOver();
Answer by Sildaekar · Mar 10, 2014 at 06:33 PM
This:
HighScores3 scriptref = reference2.GetComponent < HighScores3>().GameOver;
Should be this:
HighScores3 scriptref = reference2.GetComponent < HighScores3>().GameOver();
Answer by Perrymanon · Mar 11, 2014 at 01:31 AM
Thank You both very much, I had actually noticed the missing brackets after posting this. I was already assigning the script to a variable in awake, it was calling it correctly that I had missed. It now works as it should.
Thank you very much.
Your answer
![](https://koobas.hobune.stream/wayback/20220613135913im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to put a reference on a prefab through the script ? 1 Answer
Delegates versus class references 1 Answer
The referenced script (CameraContoller) on this Behaviour is missing! 1 Answer
Creating a button, giving it a delegate (or Action), and giving that delegate a reference parameter 0 Answers
How to shoot a bullet based on another object's position? 1 Answer