EDIT
Figured it all out.
ORIGINAL
I am trying to make a simple game where there is a GUI with two text fields and a button ... player enters in angle and force into the two text areas and presses the button to launch an object forward (in x-direction) with player defined angle and force.
I running into a few problems. First off here is what I have so far:
var force:int;
var angle:int;
//var prefabBanana:Transform;
var temp:int;
var temptwo:int;
var prefabBanana : GameObject;
//var gorilla : GameObject;
var elevationAngle : Vector3;
var throwForce : int;
function OnGUI ()
{
if(GUI.Button(Rect(10, 50, 80, 20), "Launch!!")) {
Launch();
}
var text = GUI.TextField(Rect(10, 10, 50, 20), angle.ToString());
var texttwo = GUI.TextField(Rect(10, 30, 50, 20), force.ToString());
if (int.TryParse(text, temp)){
angle = Mathf.Clamp(0, temp, 360);
}
else if (text == "") angle = 0;
if (int.TryParse(texttwo, temptwo)){
force = Mathf.Clamp(0, temptwo, 360);
}
else if (texttwo == "") force = 0;
}
function Launch()
{
elevationAngle = Vector3(angle,0,0);
throwForce = force;
var banana : GameObject = Instantiate(prefabBanana, transform.position, Quaternion.identity);
var elevation : Vector3 = Quaternion.Euler(elevationAngle) * transform.forward;
new banana.rigidbody.AddForce(elevation * throwForce);
}
I getting this error when I attempt to launch the object:
"InvalidCastException: Cannot cast from source type to destination type. fire.Launch () (at Assets/fire.js:40) fire.OnGUI () (at Assets/fire.js:15)
Nothing happens, the object is never launched, but the game runs fine and the script compiles fine.
Any ideas on what is wrong? Sorry I am not the best programmer out there!!
Thanks!!
"declaring your banana" lol
– anon49000424