Question by
kojunha · Sep 01, 2015 at 08:33 AM ·
c#javascriptchangeconvert
How can I change this java to C#
var GameObject TargetA; var GameObject TargetB;
var float speed = 0.1f;
function FixedUpdate () {
var weigt = Mathf.Cos (Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
transform.position = TargetA.transform.position * weigt + TargetB.transform.position * (1 - weigt);
}
}
Comment
Best Answer
Answer by Mikilo · Sep 01, 2015 at 08:39 AM
Hello.
public GameObject TargetA;
public GameObject TargetB;
public float speed = .1F;
protected virtual void FixedUpdate()
{
var weight = Mathf.Cos(Time.time * speed * 2F * Mathf.PI) * .5F + .5F;
transform.position = TargetA.transform.position * weight + TargetB.transform.position * (1F - weight);
}
You are welcome.
By the way, this is not really appropriate to come and only ask for code. This is not even a question.
Answer by BlackSnow_2 · Sep 01, 2015 at 08:40 AM
The thing about Unity is that a large amount of the differences between C# and Javascript while using the Unity API are trivial. They mostly relate to calling functions and such (if, while, foreach, etc.).
public float speed = 0.1f;
void FixedUpdate () {
var weigt = Mathf.Cos (Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
transform.position = TargetA.transform.position * weigt + TargetB.transform.position * (1 - weigt);
}
That should work as long as you have a TargetA and TargetB.
Your answer
Follow this Question
Related Questions
JavaScript to C# 1 Answer
UnityScript to C# Conversion 1 Answer
Convert Java to C# 2 Answers
Convert a java script in a c#??? thank you 1 Answer
Raycast variable type in C#? 1 Answer