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 feel if I would have done this is C# I wouldn't run into this problem, however I am forcing myself to learn JS" - Just out of interest, why are you making yourself use Unityscript if you already know C#? Most people regard C# as a "superior" language, and it's certainly a more transferrable skill...?
– tanoshimiThat confused me too. It's not even legit JS. It isn't a crossover skill outside of Unity.
– flaviusxviiShould I just stick to C#? I'm finding this language to fight me at every turn unlike C#.
– ChinchyI use and prefer C#. It's lovely.
– flaviusxvii