- Home /
How do you translate transform js>c#
How do you translate transform (eks. down below) js>c# ?
function Update()
transform.Translate(Vector3.forward * Time.deltaTime * mySpeed);
myDist += Time.deltaTime * mySpeed;
if(myDist >= myRange)
Destroy(gameObject);
Oddly enough, that code looks to me like it should compile as-is in either JS or C# (I'd test, but I'm not at a machine with Unity installed). If you open the console log, do you see any error messages? What are you trying to do that isn't working?
I agree with @rutter. This should compile. You are missing the '{' and '}' for the Update() function. Just take the lines of code starting with 'transform.Translate()...' and past them into a new C# script.
Answer by Penzin · Apr 05, 2014 at 07:07 AM
The only real difference with this code is that you need to statically define the return type of Update() in C#.
public void Update()
{
this.transform.Translate((Vector3.forward * mySpeed) * Time.deltaTime);
myDist += (mySpeed * Time.deltaTime);
if(myDist >= myRange)
{
this.Destroy(this.gameObject);
}
}
Your answer
Follow this Question
Related Questions
I need this translated(Js to C#). 1 Answer
how to move an object (noob) 2 Answers
Problem Javascript to C# 3 Answers
How do I modify the current transform? 2 Answers
Translate code from C# to Javascript 1 Answer