- Home /
I need help toggling a main menu button.
I am trying to make a main menu button that toggles VSync. I am also trying to make it change the text for a text mesh. This is my script:
var VSyncButton = false;
function OnMouseEnter()
{
//Change the color of the text
renderer.material.color = Color.green;
}
function OnMouseExit()
{
//Change the color of the text
renderer.material.color = Color.white;
}
function OnMouseUp() {
if ( VSyncButton )
{
QualitySettings.vSyncCount = 1;
GetComponent(TextMesh).text = "VSync: True";
}
}
How would the VSync count be toggled? I tried different methods but none of them worked...
The VSync. I am trying to toggle the vsync count from 1 to 0 and from 0 to 1.
Answer by mhughson · Sep 05, 2012 at 01:06 AM
If I understand your question, is it just a matter of adding an else statement?
if ( VSyncButton )
{
if( QualitySettings.vSyncCount == 0 )
{
QualitySettings.vSyncCount = 1;
GetComponent(TextMesh).text = "VSync: True";
}
else
{
QualitySettings.vSyncCount = 0;
GetComponent(TextMesh).text = "VSync: False";
}
}
Have you tried putting a break point in and seeing what is happening? Is the vSync being set as you expect, or is it skipping over that code altogether?
It's skipping the code. It only gets set to 1. It will not toggle back to 0.
Answer by Griffo · Sep 05, 2012 at 06:37 PM
function OnMouseUp() {
if ( VSyncButton ) {
QualitySettings.vSyncCount = 1;
GetComponent(TextMesh).text = "VSync: True";
}
else
{
QualitySettings.vSyncCount = 0;
GetComponent(TextMesh).text = "VSync: False";
}
}
I tried using that and it also did not seem to work. I think the "else" needs to be connected to "VSyncButton". I tried doing that but it gave me some errors.