- Home /
convert C# script to java
can anyone convert this script in to a java one
using UnityEngine;
using System.Collections;
public class AutoAI : MonoBehaviour { public float speed = 20; public float rotatespeed = 10; public float dis = 1; public float LeftRight = 2; public float infront = 1; private int direction = 60;
// Use this for initialization void Start () {
}
// Update is called once per frame void Update () {
if(!Physics.Raycast(transform.position, transform.forward, infront)){
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
else{
if(!Physics.Raycast(transform.position, -transform.right, LeftRight)){
direction = 1;
}
else if(!Physics.Raycast(transform.position, transform.right, LeftRight)){
direction = -1;
}
transform.Rotate(Vector3.up, 60 * rotatespeed * Time.deltaTime * direction);
}
}
}
Answer by Jesse Anders · Dec 27, 2010 at 06:47 PM
The 'code' formatting feature doesn't seem to work correctly all the time, but if you post code and find that it hasn't been formatted correctly, please edit your post and try to fix it (assuming you haven't already).
As for your request, Java (not 'java') isn't supported in Unity; what you're most likely referring to is UnityScript (aka 'javascript', although it still isn't 'real' javascript), which is a different language entirely.
What I'd recommend is that you attempt the conversion yourself, and then post here or to the forums with specific questions if you run into problems.
I don't use UnityScript so I can't guarantee correctness here, but here's a few tips to get you started:
- Remove the 'using' statements and the class declaration.
- Replace variable declarations of the forum 'public [type] [name] = [initial value]' with 'var [name] : [type] = [initial value]'.
- Replace '[return type] [function name]()' with 'function [function name]()'.
Obviously there's a lot more to it than that, but that should at least get you started on porting the script you posted above.
that looks good, i use UnityScript, and not c# but basically void = function or private void or function = function in Unityscript, also, "bool" = boolean u have to spell it out. and there's special ways to say the body of the script that is different than c# (i recommend checking the reference to make sure it's okay.)
And for the function return type in UnityScript => function [function name]() : [return type]
Your answer

Follow this Question
Related Questions
having prob while accessing java boolean from c# script 1 Answer
How to make a C# script to JavaScript 1 Answer
Need help with C# to Unityscript 3 Answers
What am I doing wrong 1 Answer