- Home /
Help...convert C# to Js ???
Hello
I try to convert it but doesn't work.. Any help>>>>
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Test5 : MonoBehaviour {
public List<Transform> targets;
// Use this for initialization
void Start () {
targets = new List<Transform>();
AddAllenmey ();
}
public void AddAllenmey ()
{
GameObject[] go = GameObject.FindGameObjectsWithTag("wall");
foreach(GameObject wall in go)
{
AddTarget(wall.transform);
}
}
public void AddTarget(Transform wall)
{
targets.Add(wall);
}
// Update is called once per frame
void Update () {
}
}
I don't understand. Why would you ever want to to that?
Answer by jahroy · Oct 20, 2011 at 07:20 AM
The best way to learn would be to do it yourself, not have other people do it for you.
I'll give you a few hints (that are well documented here, here, here, etc...):
- For javascript you use import System.IO instead of using System.IO (in javascript you don't use the term using at all).
- When you declare a function in javascript, you use the keyword function and you are not required to declare its return type. In other words, you would use function Start() in stead of void Start()
- In javascript there is no need to type : MonoBehaviour when you declare a class. Scripts written in javascript extend the MonoBehaviour class by default.
- There are a few other basic syntax differences that are highlighted by the script you've posted. I can't think of a better way for you to learn javascript than to discover them by reading some documentation... That's the best way to learn Unity!
- Good luck!
In regards to #2: You can declare its return type, though you apparently don't have to:
function PlusOne(a:int):int{
var result:int;
result=a+1;
return result;
}
I find it good practice to always declare its return type, for readability's sake and for catching incompatible-type errors further up the road that might occur when assigning its return value to some variable.
Absolutely... You're right. Thanks.
You can explicitly declare the type of everything in Unity javacript, which is quite cool.
I do the same, but was trying to keep is brief and simple above.
I changed the wording of my answer :)
Answer by roamcel · Oct 19, 2011 at 07:16 PM
Javascript and c# can exist simultaneously in the same project. Be sure that you actually need to convert this before facing the woes of learning a new language :)
But I want to know how I do this in Java Script>> I mean [Array] (GameObject)....
Answer by ScriptGirl · Oct 20, 2011 at 05:08 PM
There is a utility available specifically for this. I haven't tested it but here is the link: Online UnityScript/Javascript to C# converter
Your answer
![](https://koobas.hobune.stream/wayback/20220613013959im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
js to c# conversion 1 Answer
Help with conversion from javascript to c# 3 Answers
VMD motion to FBX anim 0 Answers