- Home /
People
Why can't I pass in void when trying to connect scripts?
On line 11 I try to call the script PlayerCustomizationMenu ,but it won't take the return value of void. The error goes as so: Assets/Scripts/mainMenuOptions.cs(11,46): error CS1525: Unexpected symbol )', expecting
.'
and here's the script
public class mainMenuOptions : MonoBehaviour
{
public bool mMOOn = false;
public GUIStyle optionsButton;
void Start ()
{
PlayerCustomizationMenu (void);
}
void Update ()
{
}
void OnGUI()
{
if(GUI.Button(new Rect(100,100,250, 50),"Options", optionsButton))
{
if(mMOOn == false)
{
mMOOn = true;
pCMOn = false;
sBroOn = false;
}
}
}
}
Are you trying to call another script or another function within this script?
Part of the problem is the object oriented nature of using Unity. Unless the object is a Singleton, or static, you will need to reference an instance of the object before you call any functions. Also, if I take your comments literally you cannot directly call a script, only the methods of said object can be called.
Answer by mattyman174 · Mar 08, 2014 at 04:28 AM
You cant pass void as a function parameter.
If the function is ment to accept a parameter but you want that value to be nothing, just pass a default or unaccepted value and check for it in the function.
If it accepts no parameters then what your trying to do in theory is the same as the following.
PlayerCustomizationMenu ();
Even when i just pass in int or string or something of the sorts it still just says error CS1525: Unexpected symbol )', expecting
.'. And if I leave it empty it says Assets/Scripts/main$$anonymous$$enuOptions.cs(11,45): error CS1525: Unexpected symbol )', expecting
.'
See my comment on your answer as to why it's not working. Can you post the script you are trying to call?
Your trying to call a Class. You cant do that.
I assume you have little to no $$anonymous$$nowledge on c# program$$anonymous$$g.
I recommend you follow some basic Tutorials on c# program$$anonymous$$g on the Internet. You can find many helpful tutorials by googling.
If your trying to access the Static $$anonymous$$ember of that Class do it the following way.
PlayerCustomization$$anonymous$$enu.pC$$anonymous$$On;
Look, it's quite clear you don't have a clue how object orientation works. You claim to not be new to C#, but that doesn't mean you're good at it, or understand it. The suggestion of looking at some basic tutorials has been the best one so far. Pretty much everything you've said so far is nonsense.
I'm sure nobody here is out to insult you. They are not complaining about what you don't know, but the fact you are arguing with them about what you don't know. Here's some free advice on asking for help:
Be realistic about what you know and what you need to learn (Don't say you know something when you clearly don't).
When someone corrects you, don't get defensive. You will stop yourself from learning something new.
When someone is trying to help you, don't reject their advice.
I have always found the community to be helpful and kind. I'm not sure why you have been so resistant to the answers that have been provided, when they clearly solve your problem. Please don't take this in an aggressive tone, we're all just trying to help you.
Answer by fifthknotch · Mar 08, 2014 at 04:36 AM
You may check out:
http://answers.unity3d.com/questions/7555/how-do-i-call-a-function-in-another-gameobjects-sc.html
I believe it expands upon what your question is about.