x


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

more ▼

asked Sep 05 '11 at 08:54 PM

AASonyKK gravatar image

AASonyKK
36 2 3 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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

more ▼

answered Sep 05 '11 at 10:04 PM

SilverTabby gravatar image

SilverTabby
1.9k 3 6 18

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.

Sep 05 '11 at 10:31 PM AASonyKK

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!!!

Sep 06 '11 at 12:36 PM AASonyKK
(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:

x4375
x3420
x264

asked: Sep 05 '11 at 08:54 PM

Seen: 762 times

Last Updated: Sep 06 '11 at 12:36 PM