Hi want i want my code to do is only access and activate the gravity on the rigidbody if blue 1 && blue 2 == true, but i can’t find anywhere how to create a gui button inside of an if statemen thats not in an OnGUI() function? Here’s my code if you could please help me I would greatly appreciate it!!(:
var blue2 = false;
var red2 = false;
var destroyedObject : GameObject;
var myLevelResetLost : String;
var myLevelResetWin : String;
var rigidbodyTrigger : Rigidbody;
function OnTriggerEnter (mycollider : Collider) {
if(mycollider.tag == "Blue1"){
blue1 = true;
Debug.Log("blue1");
}
if(mycollider.tag == "Red2"){
blue2 = true;
Debug.Log("red2");
}
if(blue1 && red2 == true){
Debug.Log("It worked");
}
}
function OnGUI()
{
if (GUI.Button(Rect(10,70,100,40),"Drop Ball"))
{
attachedRigidbody = rigidbodyTrigger.rigidbody;
attachedRigidbody.useGravity = true;
}
}
function OnCollisionEnter(mycollision : Collision)
{
if (mycollision.gameObject.tag == "Door")
{
Destroy(destroyedObject, 1);
Application.LoadLevel(myLevelResetLost);
}
if(mycollision.gameObject.tag == "EndGame")
{
Application.LoadLevel(myLevelResetWin);
}
}