- Home /
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
whell u are right and thank you but the problem is still there
Answer by hijinxbassist · Jun 01, 2012 at 02:04 AM
For a click you can use the MonoBehaviour function http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseUpAsButton.html>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;
}
@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 $$anonymous$$m and their ongoing effort to make ga$$anonymous$$g easier from a game devs POV. One of these days im sure ill need it, for now i just preach it :)