I’m having issues with a bit of script that compares two floats. The first float is taken from an objects rotation and the second float is between a set of variances given by a sub script.
Here is the full script
Side note: this script is being used on multiple surfaces. so when comparison statement is true that Animation will play. I’m not sure
if this will be an issue on it’s own.
#pragma strict
//first three variables are temporary variables that allow a sub function to give a range
// to be used later to see if the cube’s rotation is within the range.
public var xRot : float;
public var yRot : float;
public var zRot : float;
public var machineSound : AudioClip;
public var box : GameObject;
private var upIdle = false;
private var downIdle = false;
private var interval: float = 1;
private var lessThanXrot = 0.0;
private var greaterThanXrot = 0.0;
private var lessThanYrot = 0.0;
private var greaterThanYrot = 0.0;
private var lessThanZrot = 0.0;
private var greaterThanZrot = 0.0;
function Start ()
{
// it seemed that I had to set these secondary variables before the comparison instead of setting them within the comparison
lessThanXrot = withinVarianceLess(xRot);
greaterThanXrot = withinVarianceGreater(xRot);
lessThanYrot = withinVarianceLess(yRot);
greaterThanYrot = withinVarianceGreater(yRot);
lessThanZrot = withinVarianceLess(zRot);
greaterThanZrot = withinVarianceGreater(zRot);
}
function Update ()
{
if(box.transform.rotation.eulerAngles.x > lessThanXrot ||
box.transform.rotation.eulerAngles.x < greaterThanXrot
box.transform.rotation.eulerAngles.y > lessThanYrot ||
box.transform.rotation.eulerAngles.y < greaterThanYrot
box.transform.rotation.eulerAngles.z > lessThanZrot ||
box.transform.rotation.eulerAngles.z < greaterThanZrot)
{
\Play Animation:: Issue is here it always plays the animation. It does not matter if
}
else
{
\Play other Animation:: I haven’t been able to get this to trigger
}
}
//This secondary function is made so that I don’t have to have a bunch of scrips with each case typed in as a static variable
function withinVarianceLess(rot : float): float
{
if(rot == 0)
{
return 10.0;
}
if(rot == 90)
{
return 100.0;
}
if(rot == 180)
{
return 190.0;
}
if(rot == 270)
{
return 280.0;
}
}
function withinVarianceGreater(rot : float): float
{
if(rot == 0)
{
return 350.0;
}
if(rot == 90)
{
return 80.0;
}
if(rot == 180)
{
return 170.0;
}
if(rot == 270)
{
return 260.0;
}
}