x


Hey, i need help with GUI text ibn javascript

hey, Im making a code for a multiple choise question but for some reason when i drag the mouse over it , it does change coler but when i click, it does not, what could be going on?

pragma strict

var correct = true;
var answer = true;
var wrong = false;
var locking = false;

function Start () {
Screen.lockCursor = true;
}

function Update () {
Screen.showCursor = false;
// center mouse   
    if (Input.GetKeyDown(KeyCode.P))
        if (Screen.lockCursor)
        Screen.lockCursor = false;

    else{
    Screen.lockCursor = true;
    }
//if correct
    if (Input.GetButtonDown("fire1")&& answer)
    {
    renderer.material.color = Color.green;
    locking = true;
    }
    if (Input.GetButtonDown("fire1")&& wrong)
    {
    renderer.material.color = Color.red;
    locking = true;
    }
    if (wrong && answer)
    {
    answer = false;
    }

}
// change color when mouse is on
function OnMouseEnter ()
    {
    if (locking = false)
       renderer.material.color = Color.red;
    }

function OnMouseExit ()
    {
    if loking = false; 
       renderer.material.color = Color.white;
    }
thanks a lot
more ▼

asked Jun 01 '12 at 01:21 AM

thenachotech1113 gravatar image

thenachotech1113
131 2 12 22

Dose OnMouseDown works?

Jun 01 '12 at 01:37 AM sooncat

whell u are right and thank you but the problem is still there

Jun 01 '12 at 02:09 AM thenachotech1113
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

For a click you can use the MonoBehaviour function OnMouseUpAsButton , which on click will change the color when the user releases the button.

function OnMouseUpAsButton()
{
    if(correct)renderer.material.color = Color.green;
    else renderer.material.color = Color.red;
}
more ▼

answered Jun 01 '12 at 02:04 AM

hijinxbassist gravatar image

hijinxbassist
2k 23 31 38

thanks a lot man

Jun 02 '12 at 12:51 AM thenachotech1113

@thenachotech no prob, this is one of those functions that takes ray casting out of the equation. I have never used it :p but i know its there and how handy it can be.

Thanks to the unity dev team and their ongoing effort to make gaming easier from a game devs POV. One of these days im sure ill need it, for now i just preach it :)

Jun 02 '12 at 04:12 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:

x3689
x984
x553
x275
x2

asked: Jun 01 '12 at 01:21 AM

Seen: 277 times

Last Updated: Jun 02 '12 at 04:12 AM