- Home /
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;
}
}
}
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)
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 :
Your answer
Follow this Question
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