I’ve tried putting them in 2 separate functions, and deactivating one raytrace through a boolean if statement, but I still can’t get both of them to work. Both of them should work, but why is only one of them working and not both of them?
#pragma strict
var Strength : float = 0.004;
var MinHeight : float = 2;
var MaxHeight : float = 10;
var ReadHeight : boolean;
function FixedUpdate () {
if (ReadHeight == true){
ReadHigh();
}
if (ReadHeight == false){
ReadLow();
}
}
function ReadHigh () {
if (Physics.Raycast (transform.position + Vector3(0,0,0), transform.up, MaxHeight)) {
rigidbody.AddForce(Vector3.up * 0);
} else {
rigidbody.AddForce(Vector3.up * -Strength);
}
}
function ReadLow () {
if (Physics.Raycast (transform.position + Vector3(0,0,0), transform.up, MinHeight)) {
rigidbody.AddForce(Vector3.up * Strength);
}
}