Unity doesnt recognize public functions within a script
Hello, so the problem i'm having is that i've made two scripts where one refers to the other with
firstscript = gameObject.GetComponent<class from the first script>();
And this works fine untill i call a public function from it like this:
firstscript.publicfunctionname();
monodev recognizes the public function a proceeds to suggest said function to me. But when i enter unity i get the CS1061 error message saying that my class i referred to doesnt contain said function even though its set to public.
I've definetly done this before but i'm not sure why i'm not able to do it now. Any help would be appreciated thanks!
Have you tried to close $$anonymous$$onodevelop and restart Unity?
$$anonymous$$y best guess would be that the type of the firstscript (variable? field?) is not the type you want and that the output of gameObject.GetComponent() is returning the right type but it's being up-cast.
You can test that hypothesis by collapsing the two lines into one:
gameObject.GetComponent<class from the first script>().publicfunctionname();
If that doesn't work, can you post a distilled/sanitized version of the problem code so others can try to help in earnest?
Answer by J-F · Sep 20, 2017 at 06:23 PM
Strangely enough, The third time i restarted unity and reimported the scripts they started working properly again.
Answer by unit_nick · Sep 20, 2017 at 03:51 PM
I don't know but wouldn't a public function still need to be initialized? What if you make it static?
Your answer
Follow this Question
Related Questions
Error CS1061: Are you missing an assembly reference? 2 Answers
GameObject[] doesn't have a definition for transform/name/etc... 1 Answer
public or private, but what about no class before a variable? 3 Answers
Why cant I access a PUBLIC function (Cs, VS2015 and 2D)? Help? 1 Answer
Beginner needs Help! 1 Answer