• 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 AASonyKK · Sep 05, 2011 at 08:54 PM · c#

Script from JS to C#

I need to translate an object form A to B. I found this http://www.unifycommunity.com/wiki/index.php?title=MoveObject and it work fine but i need to convert it in C#.

If I understand the MoveObject.js can remain in js but I can't convert the example to C#

The example is it:

 function Start () {
 // Starting from the origin, move this object to 5 units along X by 10 units along Z, at 2.5 units per second
 yield MoveObject.use.Translation(transform, Vector3.zero, Vector3(5.0, 0.0, 10.0), 2.5, MoveType.Speed);
 // When that's done, simultaneously move up one unit and flip 180 degrees along the Z axis, doing both in half a second
 MoveObject.use.Translation(transform, Vector3.up, .5, MoveType.Time);
 MoveObject.use.Rotation(transform, Vector3.forward * 180.0, .5);

}

I read in C# I must write StartCoroutine, but I can't do it.

Can any help me? Thanks

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
0
Best Answer

Answer by SilverTabby · Sep 05, 2011 at 10:04 PM

 IEnumerator Start ()
 {
     // Starting from the origin, move this object
     // to 5 units along X by 10 units along Z, at 2.5 units per second
     yield return StartCoroutine
        (MoveObject.use.Translation
            (transform, Vector3.zero, Vector3(5.0, 0.0, 10.0), 2.5, MoveType.Speed));

      // When that's done, simultaneously move up one unit
      // and flip 180 degrees along the Z axis, doing both in half a second
     StartCoroutine(MoveObject.use.Translation(transform, Vector3.up, .5, MoveType.Time));
     StartCoroutine(MoveObject.use.Rotation(transform, Vector3.forward * 180.0, .5));
 }




StartCoroutine(method) --- Creates a coroutine that runs side by side this one

yield return ____________________________________________;

  • null //waits for one frame to pass and resumes during the Update calls

  • break //kills this coroutine immediately.

  • StartCoroutine(nameOfCoroutine()) //waits for nameOfCoroutine to finish

  • new WaitForSeconds(X) //waits for X seconds

  • new WaitForFixedUpdate() // waits for one frame to pass and resumes during the FixedUpdate calls

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 AASonyKK · Sep 05, 2011 at 10:31 PM 0
Share

I use this code but i take a lot of errors because the script can't find the MoveObject. I did this "Put this script in your Standard Assets/Scripts folder; this way it can be easily used from C# or Boo. The script should be named "MoveObject". The script must be attached to some object in the scene, such as an empty object used for game manager scripts" and i created a new c sharp script and I use the your answer but it don't run. But if i use the js script it work. I used:

using UnityEngine; using System.Collections;

public class Person1Move : MonoBehaviour {

 IEnumerator Start() .......

And I take the error "The name `MoveObject' does not exist in the current context"

Can this error appear beacuse the us script is in c# and the MoveObject is in JS? mmmm I need help!

I think now the question is: How can I create a C# script that can communicate with another js script? (because the MoveObject is in JS.

avatar image AASonyKK · Sep 06, 2011 at 12:36 PM 0
Share

SOLVED!!!

The C# script for see the MoveObject js script, I had to put the js script in the "Standard Assets" and not in "Standard Assets-->Scripts"

Thanks for the help!!!

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Error when referencing one script from another. 1 Answer

Distribute terrain in zones 3 Answers

Reference a JS script in a C# script? 2 Answers

Gather all coordinates of a terrain into a data structure. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges