When the one character faces 180 degrees I would like the other character to face -90 degrees. I whipped up this script but it doesn’t seem to be working.
#pragma strict
var frank : GameObject;
var bob : GameObject;
function Update ()
{
if (bob.transform.rotation.y == 180)
{
frank.transform.rotation.y = 90;
}
}
Let’s setup some Debug.Log :
#pragma strict
var frank : GameObject;
var bob : GameObject;
function Start(){
Debug.Log(bob.transform.rotation.y);
Debug.Log(bob.transform.localRotation.y);
Debug.Log(bob.transform.eulerAngles.y);
Debug.Log(bob.transform.localEulerAngles.y);
}
function Update ()
{
if (bob.transform.rotation.y == 180.0f)
{
Debug.Log("Try 1 :" + "Does it work?");
frank.transform.rotation.y = 90.0f;
}
if (bob.transform.eulerAngles.y == 180.0f)
{
Debug.Log("Try 2 :" + "Does it work?");
frank.transform.eulerAngles.y = 90.0f;
}
var v : Vector3 = bob.transform.eulerAngles;
if (v.y == 180.0f)
{
Debug.Log("Try 3 :" + "Does it work?");
frank.transform.eulerAngles.y = 90.0f;
}
v.y = 180.0f;
bob.transform.eulerAngles = v;
if (v.y == 180.0f)
{
Debug.Log("Try 4 :" + "Does it work?");
frank.transform.eulerAngles.y = 90.0f;
}
}
transform rotation is Quaterinon so its value must be between -1 and 1.
You could use :
if (bob.transform.rotation.y == 1.0f)
{
Debug.Log("Try 1 :" + "Does it work?");
frank.transform.rotation.y = 0.7071068f;
}