x


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 targets;

	// Use this for initialization

	void Start () {

		targets = new List();

		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 () {

		

	}

}
more ▼

asked Oct 19 '11 at 04:30 PM

firasdeep gravatar image

firasdeep
56 17 19 20

I don't understand. Why would you ever want to to that?

Oct 19 '11 at 04:30 PM syclamoth
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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...):

  1. For javascript you use import http://System.IO instead of using http://System.IO (in javascript you don't use the term using at all).
  2. 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()
  3. In javascript there is no need to type : MonoBehaviour when you declare a class. Scripts written in javascript extend the MonoBehaviour class by default.
  4. 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!
  5. Good luck!
more ▼

answered Oct 20 '11 at 07:20 AM

jahroy gravatar image

jahroy
3.2k 14 18 41

Thx..............

Oct 20 '11 at 08:06 AM firasdeep

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.

Oct 20 '11 at 03:53 PM blitzen

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 :)

Oct 20 '11 at 04:35 PM jahroy
(comments are locked)
10|3000 characters needed characters left

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 :)

more ▼

answered Oct 19 '11 at 07:16 PM

roamcel gravatar image

roamcel
1.2k 37 40 44

But I want to know how I do this in Java Script>> I mean Array....

Oct 20 '11 at 07:02 AM firasdeep

THX...........

Oct 20 '11 at 01:15 PM firasdeep
(comments are locked)
10|3000 characters needed characters left

There is a utility available specifically for this. I haven't tested it but here is the link: Online UnityScript/Javascript to C# converter

more ▼

answered Oct 20 '11 at 05:08 PM

ScriptGirl gravatar image

ScriptGirl
181 8 10 13

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5060
x225
x69
x7

asked: Oct 19 '11 at 04:30 PM

Seen: 1178 times

Last Updated: Oct 20 '11 at 11:05 PM