2013-11-23 5 views
2

Я уже мог отображать всплывающую подсказку на каждой кнопке всякий раз, когда кнопка мыши наводит эту кнопку. Однако функция кнопки не выполнялась, но показана всплывающая подсказка.Показать функцию кнопки подсказки всплывающей подсказки не будет работать C#

Вот код:

public static float textHeight = 25; 
    public static float textWidth = 1350; 
    public static float buttonHeight = 25; 
    public static float buttonWidth = 100; 
    public static float screenTextHeight = 745; 

public virtual void TurnOnGUI() 
    { 
     Rect buttonRect = new Rect(0, Screen.height - buttonHeight * 3, buttonWidth, buttonHeight); 
     Rect tooltipRect = new Rect(100 + 10, Screen.height - buttonHeight * 3 + 5, buttonWidth, buttonHeight); 
     Rect textRect = new Rect(10, Screen.height - screenTextHeight, textWidth, textHeight); 
     Rect _buttonRect = new Rect(0, Screen.height - buttonHeight * 2, buttonWidth, buttonHeight); 
     Rect _buttonRect_ = new Rect(0, Screen.height - buttonHeight * 1, buttonWidth, buttonHeight); 
     Rect _tooltipRect = new Rect(100 + 10, Screen.height - buttonHeight * 2 + 5, buttonWidth, buttonHeight); 
     Rect _tooltipRect_ = new Rect(100 + 10, Screen.height - buttonHeight * 1 + 5, buttonWidth, buttonHeight); 

     label1.normal.textColor = Color.red; 

     //Text Field 
     if (GUI.Button(textRect, "")) 
     { 

     } 

     //ToolTip Text 
     //GUI.Button(buttonRect, new GUIContent("Move", "Move the Player")); 
     //GUI.Label(tooltipRect, GUI.tooltip, label1); 

     GUI.tooltip = null; 
     //Move Button 
     if (GUI.Button(buttonRect, "Move")) 
     { 
      if (!moving) 
      { 
       GameManager.instance.RemoveTileHighlights(); 
       moving = true; 
       attacking = false; 
       GameManager.instance.HighlightTilesAt(gridPosition, Color.blue, movementPerActionPoint); 
      } 

      else 
      { 
       moving = false; 
       attacking = false; 
       GameManager.instance.RemoveTileHighlights(); 
      } 
     } 

     //ToolTip Text 
     //GUI.Button(_buttonRect, new GUIContent("Attack", "Attack the Player")); 
     //GUI.Label(_tooltipRect, GUI.tooltip, label1); 

     GUI.tooltip = null; 
     //Attack Button 
     if (GUI.Button(_buttonRect, "Attack")) 
     { 
      if (!attacking) 
      { 
       GameManager.instance.RemoveTileHighlights(); 
       moving = false; 
       attacking = true; 
       GameManager.instance.HighlightTilesAt(gridPosition, Color.red, attackRange); 
      } 

      else 
      { 
       moving = false; 
       attacking = false; 
       GameManager.instance.RemoveTileHighlights(); 
      } 
     } 

     //ToolTip Text 
     //GUI.Button(_buttonRect_, new GUIContent("End Turn", "End Turn the Player")); 
     //GUI.Label(_tooltipRect_, GUI.tooltip, label1); 

     GUI.tooltip = null; 
     //End Turn Button 
     if (GUI.Button(_buttonRect_, "End Turn")) 
     { 
      GameManager.instance.RemoveTileHighlights(); 
      actionPoints = 2; 
      moving = false; 
      attacking = false; 
      GameManager.instance.NextTurn(); 
     } 
    } 

Вот скриншот (парения мыши на кнопку «Переместить» и сделать красный цвет всплывающей подсказки), подсказка отображается, но когда я нажмите кнопку «Переместить», это не будет работать (не будет отображаться синяя сетка для движения):

enter image description here

Но когда я удалить текст подсказки, «Переместить» функция кнопки запуска отлично:

enter image description here

Как я могу это решить? Благодаря

ответ

1

Небольшой пример

using UnityEngine; 
using System.Collections; 

public class Demo : MonoBehaviour { 
    bool clicked = false; 

    void OnGUI() { 
     clicked = GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", "This is the tooltip")); 
     GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip); 
     if(clicked) 
     { 
     //do your stuff after click 
      print(clicked); 
     } 
    } 
} 

т.е.

public static float textHeight = 25; 
public static float textWidth = 1350; 
public static float buttonHeight = 25; 
public static float buttonWidth = 100; 
public static float screenTextHeight = 745; 

bool move=false,attack=false,endTurn=false; //Added 

public virtual void TurnOnGUI() 
{ 
    Rect buttonRect = new Rect(0, Screen.height - buttonHeight * 3, buttonWidth, buttonHeight); 
    Rect tooltipRect = new Rect(100 + 10, Screen.height - buttonHeight * 3 + 5, buttonWidth, buttonHeight); 
    Rect textRect = new Rect(10, Screen.height - screenTextHeight, textWidth, textHeight); 
    Rect _buttonRect = new Rect(0, Screen.height - buttonHeight * 2, buttonWidth, buttonHeight); 
    Rect _buttonRect_ = new Rect(0, Screen.height - buttonHeight * 1, buttonWidth, buttonHeight); 
    Rect _tooltipRect = new Rect(100 + 10, Screen.height - buttonHeight * 2 + 5, buttonWidth, buttonHeight); 
    Rect _tooltipRect_ = new Rect(100 + 10, Screen.height - buttonHeight * 1 + 5, buttonWidth, buttonHeight); 

    label1.normal.textColor = Color.red; 

    //Text Field 
    if (GUI.Button(textRect, "")) 
    { 

    } 

    //ToolTip Text 
    move = GUI.Button(buttonRect, new GUIContent("Move", "Move the Player")); 
    GUI.Label(tooltipRect, GUI.tooltip, label1); 

    GUI.tooltip = null; 
    //Move Button 
    if (move) //edited 
    { 
     if (!moving) 
     { 
      GameManager.instance.RemoveTileHighlights(); 
      moving = true; 
      attacking = false; 
      GameManager.instance.HighlightTilesAt(gridPosition, Color.blue, movementPerActionPoint); 
     } 

     else 
     { 
      moving = false; 
      attacking = false; 
      GameManager.instance.RemoveTileHighlights(); 
     } 
    } 

    //ToolTip Text 
    attack = GUI.Button(_buttonRect, new GUIContent("Attack", "Attack the Player")); 
    GUI.Label(_tooltipRect, GUI.tooltip, label1); 

    GUI.tooltip = null; 
    //Attack Button 
    if (attack) //edited 
    { 
     if (!attacking) 
     { 
      GameManager.instance.RemoveTileHighlights(); 
      moving = false; 
      attacking = true; 
      GameManager.instance.HighlightTilesAt(gridPosition, Color.red, attackRange); 
     } 

     else 
     { 
      moving = false; 
      attacking = false; 
      GameManager.instance.RemoveTileHighlights(); 
     } 
    } 

    //ToolTip Text 
    endTurn = GUI.Button(_buttonRect_, new GUIContent("End Turn", "End Turn the Player")); 
    GUI.Label(_tooltipRect_, GUI.tooltip, label1); 

    GUI.tooltip = null; 
    //End Turn Button 
    if (endTurn) //edited 
    { 
     GameManager.instance.RemoveTileHighlights(); 
     actionPoints = 2; 
     moving = false; 
     attacking = false; 
     GameManager.instance.NextTurn(); 
    } 
} 
+0

Спасибо, сэр, его работал сейчас ура – Kaoru

Смежные вопросы