Help with Slerp and coroutines in c#

Hi All,

I have been struggling to convert a javascript piece of code to rotate my player 90 degrees over a set amount of seconds

I have been looking at coroutines but I cant seem to wrap my head around hwo to do this. I want the rotation to happen outside the update() function as it wont be doing it all the time only when the player pushes either the left or right button.

Can someone take a look at my java code and show me how to translate this to c#.

here is the java code

function Turn(tDir)
{

IsMoving = true;
var rotDir : float = 0.0;

if (tDir) // Turn Right
{
rotDir = 90.0;
facingDir += 1;
if (facingDir > 4) { facingDir = 1; } // if we turned right while facing west we are now north
}
else // Turn Left
{
rotDir = -90.0;
facingDir -= 1;
if (facingDir <= 0) { facingDir = 4; } // if we turned left while facing north we are now west
}

// Get the old and new rotation values
var OldRotation = charCamera.transform.rotation;
charCamera.transform.Rotate(0, rotDir, 0);
var NewRotation = charCamera.transform.rotation;

// Do the rotate
var t : float = 0.0; // Movement timer
for (t = 0.0; t <= 1.0; t += (turnSpeed * Time.deltaTime))
{
charCamera.transform.rotation = Quaternion.Slerp(OldRotation, NewRotation, t);
yield;
}

//Debug.Log("Facing Direction: " + facingDir);
// Set the new rotation value
charCamera.transform.rotation = NewRotation;

// After rotate we are not moving
IsMoving = false;
}

you can change every function to void and for variables do: Type name; instead of: var name:Type;
don’t see any other problem for conversion, its hard to say since this looks partial…

edit: oh yes probably can adjust transform. rotation directly, you’ll need to cast it to a variable first in C#. you’ll get a warning it the console just google it and you’ll see how to fix it.