title: Jump Button in Unity for Canvas
body: <p>I am looking for a code or script in C# or Java to make my cube tagged as a <code>Player</code> jump, in below script.</p>
  
  <p>I have written some code and attached it to a button on canvas, but the problem is when I press and hold the button, it keeps jumping and makes an infinitly high jump.</p>
  
  <p>Here is my script written in C#</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  
  public class DownstateButton : Button
  {
  
      public void Update()
      {
          //A public function in the selectable class which button inherits from.
          if(IsPressed())
          {
              WhilePressed();
          }
      }
  
      public void WhilePressed()
      {
          var player =GameObject.FindWithTag("Player");
  
          player.transform.Translate(0, 1, 0);
  
          //It was for jump
      }
  }
  </code></pre>