- Home /
Question by
tinashee · Oct 01, 2013 at 03:37 AM ·
c#javascript
Can this be made into javascript
Can this code be translated(turned) and explained to me in java because it is very confusing. Thank you
// Increase n towards target by speed
private float IncrementTowards(float n, float target, float a) {
if (n == target) {
return n;
}
else {
float dir = Mathf.Sign(target - n); // must n be increased or decreased to get closer to target
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target-n))? n: target; // if n has now passed target then return target, otherwise return n
}
}
}
Comment
It's javascript not java - very different languages. I've updated your question.
Best Answer
Answer by whydoidoit · Oct 01, 2013 at 03:40 AM
function IncrementTowards( n : float , target : float , a : float) : float {
if (n == target) {
return n;
}
else {
var dir = Mathf.Sign(target - n); // must n be increased or decreased to get closer to target
n += a * Time.deltaTime * dir;
return (dir == Mathf.Sign(target-n))? n: target; // if n has now passed target then return target, otherwise return n
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613115116im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help with conversion from javascript to c# 3 Answers
Can someone help me translate this to c#? 1 Answer
JS to C# need help! 1 Answer
Calling a C# function from a Javascript 3 Answers