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
-3
Question by zeuo · Dec 27, 2010 at 06:09 PM ·

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);
 }

}

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
5

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.

Comment
Add comment · Show 2 · Share
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 Jesus_Freak · Dec 27, 2010 at 08:02 PM 0
Share

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

avatar image Berenger · Dec 27, 2010 at 08:46 PM 0
Share

And for the function return type in UnityScript => function [function name]() : [return type]

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

1 Person is following this question.

avatar image

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

Moving from JS to C#, what should I know? 1 Answer


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