- Home /
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
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
I use this code but i take a lot of errors because the script can't find the $$anonymous$$oveObject. 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 "$$anonymous$$oveObject". 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 Person1$$anonymous$$ove : $$anonymous$$onoBehaviour {
IEnumerator Start() .......
And I take the error "The name `$$anonymous$$oveObject' does not exist in the current context"
Can this error appear beacuse the us script is in c# and the $$anonymous$$oveObject 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 $$anonymous$$oveObject is in JS.
SOLVED!!!
The C# script for see the $$anonymous$$oveObject 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
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error when referencing one script from another. 1 Answer
Reference a JS script in a C# script? 2 Answers
Distribute terrain in zones 3 Answers
how can convert this in js? 1 Answer