x


How to activate a object with GUI button? (java script)

I want activate a Object with GUI button: 1. Firt the Object is deactive 2. Player collusion a Trigger, Trigger activate a GUI button. 3. If I click GUI button, the Object is active. So GUI button activate the Object.

Please help with javascript for the GUI button.

more ▼

asked May 31 '12 at 10:46 AM

gordeszkakerek gravatar image

gordeszkakerek
11 7 8 10

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I don't know why I can't use ,,Vote Up" button...BUT THANKS! I'TS WORK AND HELPED ME A LOT! THANK YOU!

more ▼

answered Jun 08 '12 at 04:14 PM

gordeszkakerek gravatar image

gordeszkakerek
11 7 8 10

(comments are locked)
10|3000 characters needed characters left
//Inactive Objects script
//Inactive obj has isTrigger Collider attached

public var myMenu:MyMenu;

function OnTriggerEnter(other:Collider)
{
    if(other.CompareTag("Player"))
    {
        myMenu=other.GetComponent(MyMenu);
        myMenu.showActivateButton=true;
        myMenu.objectToActivate=gameObject;
    }
}
function OnTriggerExit(other:Collider)
{
    if(other.CompareTag("Player"))
    {
        myMenu.showActivateButton=false;
    }
}

//MyMenu.js

public var objectToActivate:GameObject;
public var showActivateButton:boolean;

function OnGUI()
{
    if(showActivateButton)
    {
        if(GUI.Button(myRect,"Activate Object")
        {
            objectToActivate.active=true;
            showActivateButton=false;
        }
    }
}

This relies on: MyMenu.js is a component on the player, the trigger is on the inactive object, player is tagged as "Player",

more ▼

answered May 31 '12 at 08:41 PM

hijinxbassist gravatar image

hijinxbassist
2.1k 23 31 38

@gordeszkakerek Mind posting that answer you posted as a comment (helps others looking at this post). Once you have posted as comment(comment button is at the bottom of my post on the right side over there >>> "Add new comment") Copy/Paste what you said there to a new comment, and if you want, select the Check Mark under the "Down Thumb" in the top right <^^< of my post to select this answer as the 'correct' answer. Helps ppl find relevant answers to their questions. Glad to help, keep coding!

Jun 18 '12 at 07:09 AM hijinxbassist
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1123
x1019
x81
x21

asked: May 31 '12 at 10:46 AM

Seen: 674 times

Last Updated: Jun 18 '12 at 07:09 AM