Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Dec 07, 2012 at 02:52 PM by Eeppi for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Eeppi · Nov 30, 2012 at 08:52 AM · networkingmultiplayermenucalling

Calling variables and functions

I made these scripts when i was using unity 3, now i'm using unity 4, but i can't understand why this isnt working now? This worked before updating...

 var multiplayerscript;
 multiplayerscript = GameObject.Find("Networking").gameObject.GetComponent(CoOp);

And I use this for things like this:

 multiplayerscript.startServer();

Error message for that was: Assets/Scripts/Menu/Menu.js(14,19): BCE0019: 'startServer' is not a member of 'Object'.

I dont think you need this part of networking script, but i'll show it too. So I was calling this function:

 function startServer(){
 Network.InitializeServer(2,menuscript.remotePort, !Network.HavePublicAddress);
 MasterServer.RegisterHost(gameName, "blabla", "blabalabal");
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image loopyllama · Nov 30, 2012 at 12:57 PM 0
Share

GameObject.Find returns a GameObject. the above code does a: gameObject.gameObject.GetComponent(). you can remove the middle "gameObject" part. I do not know javascript well so that is the other thing that is glaring to me.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by flamy · Nov 30, 2012 at 01:14 PM

 var multiplayerscript:CoOp;
 multiplayerscript = (CoOp) GameObject.Find("Networking").gameObject.GetComponent(CoOp);
 multiplayerscript.startServer();

This one should work. Declaring as var multiplayerscript will create object of Object class that holds any datatype. Sp always specify the class name while declaring.

The casting in the second line is just in case if it doesnt work. it wont be error if u remove it too.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eeppi · Nov 30, 2012 at 01:23 PM 0
Share

No errors now, but when I press start server and run that startServer function, it shows this:

InvalidCastException: Cannot cast from source type to destination type. Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible) Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value) Boo.Lang.Runtime.RuntimeServices.UnboxInt32 (System.Object value) CoOp.startServer () (at Assets/Scripts/Co-op/CoOp.js:14) $$anonymous$$enu.OnGUI () (at Assets/Scripts/$$anonymous$$enu/$$anonymous$$enu.js:14)

I can't understand what is wrong with these lines..

CoOp line 14: Network.InitializeServer(2,menuscript.remotePort, !Network.HavePublicAddress);

$$anonymous$$enu line 14: multiplayerscript.startServer();

avatar image flamy · Nov 30, 2012 at 01:24 PM 0
Share

you can select as accepted answer, if that was useful :)

avatar image flamy · Nov 30, 2012 at 01:34 PM 0
Share

Network.InitializeServer(2,menuscript.remotePort, !Network.HavePublicAddress());

HavePublicAddress is an function u missed (). generally in unity what ever name starts with Capital, it will be function of a class and others are variables of the class.

avatar image Eeppi · Nov 30, 2012 at 02:26 PM 0
Share

Thanks, but it didnt fix the problem :/.

avatar image fafase · Nov 30, 2012 at 02:38 PM 0
Share

Try with:

 multiplayerscript = GameObject.Find("Networking").GetComponent(CoOp);
Show more comments

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Main Parameters of MP game for Clients to Join 0 Answers

Multiplayer pause menu won't disappear 0 Answers

Network Tutorial Interpolation - TPS Auth 0 Answers

The magic key to networking? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges