• 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
0
Question by darkcookie · Apr 13, 2012 at 01:48 AM · c#javatranslate

Need Help Translating into Java

can some one please help me translate this script that my teacher wrote into java??? ...its in c#...but Im not custom too all the functions of C# so can some one please help me?

the script:

 using UnityEngine;
 using System.Collections;
 
 public class EnemyAI : MonoBehaviour {
     public Transform target;
     public int moveSpeed;
     public int rotationSpeed;
     public int maxDistance;
     
     private Transform myTransform;
     
     void Awake ()
     {
         myTransform = transform;
     }
     // Use this for initialization
     void Start () {
         GameObject go = GameObject.FindGameObjectWithTag("Player");
         target = go.transform;
     
     }
     
     // Update is called once per frame
     void Update () {
         
         float distance = Vector3.Distance(target.transform.position, transform.position);
         myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position),rotationSpeed * Time.deltaTime);
         if(distance < 20f && Vector3.Distance(target.position, myTransform.position) > maxDistance)
         {
             Debug.DrawLine(target.position, myTransform.position, Color.blue);
             
             
                  animation.Play("run");    
     
                  myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;    
         
         }
         else
         {
             animation.CrossFade("idle",1.0f);
         }
     }
 }
Comment
Add comment · Show 4
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 GC1983 · Apr 16, 2012 at 01:29 AM 0
Share

the f's in JS isnt a big deal. It isnt really necessary for JS, but it doesnt hurt them to be there.

avatar image Eric5h5 · Apr 16, 2012 at 01:45 AM 0
Share

Java is not interchangeable with Javascript, and Unity doesn't use Java. (Or Javascript for that matter, but that's what it's called unfortunately.)

avatar image GC1983 · Apr 16, 2012 at 01:57 AM 0
Share

False. Unity uses JavaScript. It wouldnt be called JavaScript if it wasnt. Essentially, its called UnityScript because it uses the JS syntax with a bit of change into their own style. In the end it still uses the JS syntax.

avatar image Eric5h5 · Apr 16, 2012 at 02:05 AM 0
Share

@GC83: False. It's not Javascript, and it doesn't really use the Javascript syntax. I can call my nose "Javascript", but that doesn't make it so. Unityscript was only called Javascript for marketing reasons (which I think backfired, since you can find many topics where people took that at face value, and get frustrated about their Javascript code not working in Unity).

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by GC1983 · Apr 13, 2012 at 02:19 AM

 public target : Transform;
 public moveSpeed : int;
 public rotationSpeed : int;
 public maxDistance : int;

 private myTransform : Transform;

 function Awake ()
 {
    myTransform = transform;
 }
 // Use this for initialization
 function Start () {
    var go = GameObject.FindGameObjectWithTag("Player");
    target = go.transform;

 }

 // Update is called once per frame
 function Update () {

    float distance = Vector3.Distance(target.transform.position, transform.position);
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position),rotationSpeed * Time.deltaTime);
    if(distance < 20f && Vector3.Distance(target.position, myTransform.position) > maxDistance)
    {
      Debug.DrawLine(target.position, myTransform.position, Color.blue);

             animation.Play("run");   

             myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;    
     }
    else
    {
      animation.CrossFade("idle",1.0f);
    }
 }
Comment
Add comment · Show 3 · 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 darkcookie · Apr 13, 2012 at 03:09 AM 0
Share

thk you very much:)

avatar image AlucardJay · Apr 13, 2012 at 03:13 AM 0
Share

looks good, but remove all the 'f' s, this is declaring a float in C#. If you want to announce a float in js, make sure you declare it in the var setup : float. Or for numbers on the fly , simply use a decimal value e.g. 2.5

avatar image Eric5h5 · Apr 16, 2012 at 01:44 AM 0
Share

@alucardj: It's not necessary to remove the fs. They're not needed to indicate a float in JS, but it won't cause problems to leave them. It's also not necessary to specify float when declaring a variable. As long as you use a float value (var setup = 0.0), then it's a float.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

translate javascript for loop to C# 2 Answers

Can you send Variables from C# to Unity? 1 Answer

can someone translate this to java I've tried a thousand time but couldn't do it 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