I’m making a game in which the player can fly, but my script is not working. It seems correct, throws no errors, but still does nothing. It looks like this:
#pragma strict
static var jumpHeight = 100000000000;
private static var flightParent : GameObject;
Debug.Log ("Flying");
public static function fly () {
var flightRigidbody : Rigidbody[];
if(flightParent == null) {
flightParent = GameObject.Find("FPSController");
Debug.Log ("Found Player to Fly");
}
flightRigidbody = flightParent.GetComponents.<Rigidbody>();
for (var parentFlight : Rigidbody in flightRigidbody) {
Debug.Log ("You Flapped your Wings");
parentFlight.velocity.y = jumpHeight;
Debug.Log ("Succesfull flight");
}
}
and is being called by:
if (Input.GetKey(KeyCode.Space))
{
if (MainScript.flying == true)
{
FlightScript.fly ();
}
}
All Debug.Logs are being thrown successfully. It may be noteworthy that the standard FPSCharacter is also being used in this project.