【问题标题】:Disable the GUI when the character moving角色移动时禁用 GUI
【发布时间】:2013-12-11 14:52:18
【问题描述】:

我已经让玩家角色移动到它是目的地(动画角色移动到那个目的地),我想在玩家角色移动时禁用 GUI 按钮,但我无法得到它并工作它出去。你们能帮帮我吗?

代码如下:

public class UserPlayer : Player 
{
    public override void TurnUpdate()
    {
       //Moving animation
       if (positionQueue.Count > 0) 
        {
          GUI.enabled = false; // This is the one that i want when the character still moving (animation still moving), disabled the GUI. But i can't get it
          transform.position += (positionQueue[0] - transform.position).normalized * moveSpeed * Time.deltaTime;

          if (Vector3.Distance(positionQueue[0], transform.position) <= 0.1f) 
          {
             transform.position = positionQueue[0];
             positionQueue.RemoveAt(0);

          if (positionQueue.Count == 0) 
          {
              actionPoints--;
          } 
         }
       }

       base.TurnUpdate();
    }

    public override void TurnOnGUI() 
    {
        base.TurnOnGUI();
    }
}

public class Player : MonoBehaviour 
{
    //for movement animation
    public List<Vector3> positionQueue = new List<Vector3>();

    public virtual void TurnUpdate()
    {
       if (actionPoints <= 0) 
        {
            actionPoints = 2;
            magicAttacking = false;
            moving = false;
            attacking = false;      
            GameManager.instance.NextTurn();
       }
    }

     public virtual void TurnOnGUI()
      {
        if (GameManager.instance.currentPlayerIndex == 0 || GameManager.instance.currentPlayerIndex == 2)
        {
            //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)
            {
               if (!moving)
               {
                  GameManager.instance.RemoveTileHighlights();
                  moving = true;
                  attacking = false;
                  GameManager.instance.HighlightTilesAt(gridPosition, Color.blue, movementPerActionPoint);
               }

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

【问题讨论】:

  • 禁用是什么意思?据我所见,当角色移动时,moving 参数应该阻止按钮执行任何操作。您的意思是您希望按钮不可按下并变灰,有点像窗口窗体的方式吗?

标签: c# unity3d


【解决方案1】:

您的问题已经提出,请看here

以这种方式调整您的代码:

public virtual void TurnOnGUI() {
  if (GameManager.instance.currentPlayerIndex == 0 || GameManager.instance.currentPlayerIndex == 2) {
  ...
  if(!moving) {
     move = GUI.Button(buttonRect, new GUIContent("Move", "Move the Player"));
     GUI.Label(tooltipRect, GUI.tooltip, label1);
  }      
  ...
  }
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多