# Problem with my JS, Can't rotate Cube!

So I am fairly new to JS and need some help I created this little script to rotate the object every time my 3rd person player Collider runs through certain boxes, however the code doesn’t activate, I need someone to look at at and help me out a bit. Its a very simplistic code and I feel if I would have done this is C# I wouldn’t run into this problem, however I am forcing myself to learn JS.

``````#pragma strict
public var player : Collider;
private var rotating : boolean = false;
public var rotateSpeed : int = 1;
private var leftRotate : boolean = false;
private var rightRotate : boolean = false;
public var colliderL : Collider;
public var colliderR : Collider;

function OnCollisionEnter(player : Collision)
{
if (colliderL == player)
{
leftRotate = true;
}
if (colliderR == player)
{
rightRotate = true;
}
}

function LevelRotate()
{

if (rightRotate == true)
{
if (!rotating)
{

rotating = true;

var curRot : float = 0;
var startRot : float = transform.eulerAngles.z;

while (curRot < 90)
{

curRot += rotateSpeed;

transform.eulerAngles.z = startRot + curRot;

yield;

}

transform.eulerAngles.z = Mathf.Round(startRot + 90);

rotating = false;
rightRotate = false;
}
}

if (leftRotate == true)
{
if (!rotating)
{

rotating = true;

var curRot2 : float = 0;
var startRot2 : float = transform.eulerAngles.z;

while (curRot2 > -90)
{

curRot2 += rotateSpeed;

transform.eulerAngles.z = startRot2 - curRot2;

yield;

}

transform.eulerAngles.z = Mathf.Round(startRot2 - 90);

rotating = false;
}
leftRotate = false;
}
}
``````

I don’t see you calling LevelRotate() anywhere… That’s an issue.