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 /
avatar image
0
Question by SulaimanWar · Jun 26, 2013 at 01:47 PM · c#javascriptnetworkingplayerbattle-system

I need help translating Javascript to C#

I follow a tutorial but its written in Javascript.But the GetComponenet Script I have is in C# So I used a translator but it still gives me error Here is the Javscript function Awake() {

 if (!networkView.isMine){ GetComponentInChildren(Camera).enabled = false;
  
 // disable the camera of the non-owned Player;
  
 GetComponentInChildren(AudioListener).enabled = false;
  
 // Disables AudioListener of non-owned Player - prevents multiple AudioListeners from being present in scene.
  
 GetComponentInChildren(PlayerLook).enabled = false; GetComponentInChildren(PlayerMovement).enabled = false;   
  
 }
  
 }

And here is the translated // Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden // Do test the code! You usually need to change a few small bits.

 using UnityEngine;
 using System.Collections;
 
 public class NetworkIsMine : MonoBehaviour {
 void  Awake (){
 
 
 
 if (!networkView.isMine){ GetComponentInChildren<Camera>().enabled = false; 
 
 // disable the camera of the non-owned Player; 
 
 GetComponentInChildren<AudioListener>().enabled = false; 
 
 // Disables AudioListener of non-owned Player - prevents multiple AudioListeners from being present in scene. 
 
 GetComponentInChildren<PlayerLook>().enabled = false; GetComponentInChildren<PlayerMovement>().enabled = false; 
 
 
 
 } 
 }
 }
Comment
Add comment · Show 3
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 amphoterik · Jun 26, 2013 at 01:50 PM 0
Share

What errors are you getting?

avatar image SulaimanWar · Jun 27, 2013 at 02:51 AM 0
Share

UnassignedReferenceException: The variable controller of 'Player$$anonymous$$ovement' has not been assigned. You probably need to assign the controller variable of the Player$$anonymous$$ovement script in the inspector. UnityEngine.CharacterController.get_velocity () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/NewDynamics.cs:2681) CameraBob.FixedUpdate () (at Assets/$$anonymous$$AIN - Paradox/Scripts/Player/CameraBob.cs:54)

avatar image AlucardJay · Jun 27, 2013 at 02:54 AM 3
Share

You cannot rely on a converter, you'll need to learn how to read both languages, as this will come up a lot in your journey with program$$anonymous$$g in Unity.

Check the Unity Scripting Reference, at the above-right of every script example, there is a drop-down box. Click Javascript, then select C# to see the same example in each language.

Here's some links I found useful in converting between C# and JS :

  • http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

  • http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

  • http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 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 avatar image avatar image avatar image avatar image

Related Questions

Send information from one player to another. Unity Multiplayer 2 Answers

Online Player Position 1 Answer

Player names all displayed as local player 1 Answer

Multiple Cars not working 1 Answer

how to use the listen port in this case? 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