{Unity3D] Highlight Text On Mouse Over Button Tutorial

Поделиться
HTML-код
  • Опубликовано: 31 янв 2025

Комментарии •

  • @Bishmanrock
    @Bishmanrock 4 года назад

    Thanks for this! Would have never guessed to use Target Graphic with a Text field - that's a really misleading naming structure. Now that I know, can't believe it's so straight forward.

  • @KillerGameDev
    @KillerGameDev 4 года назад +2

    Amazing! I feel like that shoulda been more clear or come prefabbed out. I mean...who the heck woulda thought that the text could go into a graphic spot?!?

  • @TheZaix12
    @TheZaix12 5 лет назад +1

    gracias es justo lo que ocupaba

  • @lora6938
    @lora6938 3 года назад

    Please tell me how to do the same thing but for a sprite (selection-highlighting) by mouse click.
    Please!🙏

    • @thesenpaicode
      @thesenpaicode  3 года назад

      For mouse click on a sprite. There's two easy ways you can change the color to simulate a highlight or change size etc. Here are a couple samples.
      So first way would be to
      if (Input.GetMouseButtonDown(0))
      {
      transform.GetComponent().sprite.color = "new color" // changes color
      transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); // changes size
      }
      if (Input.GetMouseButtonUp(0))
      {
      transform.GetComponent().sprite.color = "new color" // change back to original color
      transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); // changes back to original size
      }
      or swap out sprite with a different sprite,
      Sprite sprite;
      Sprite highlightSprite;
      if (Input.GetMouseButtonDown(0))
      {
      transform.GetComponent().sprite = highlightSprite;
      }
      if (Input.GetMouseButtonUp(0))
      {
      transform.GetComponent().sprite = sprite;
      }
      Not sure if you need mouse click, but you can also do a OnMouseOver
      Sprite sprite;
      Sprite highlightSprite;
      void OnMouseOver()
      {
      transform.GetComponent().sprite = highlightSprite;
      }
      void OnMouseExit()
      {
      transform.GetComponent().sprite = sprite;
      }
      The other way,
      void OnMouseOver()
      {
      transform.GetComponent().sprite.color = "new color"
      transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f);
      }
      you can also do a else , like so
      if(Input.GetMouseButtonDown(0)){
      // held code
      }
      else{
      // release code
      }

    • @thesenpaicode
      @thesenpaicode  3 года назад

      Although it may be more effective to use "Input.GetMouseButton(0)" instead of "Input.GetMouseButtonDown(0)" . GetMouseButton() Returns true for every frame that the mouse is being pressed.
      GetMouseButtonDown() (or GetMouseButtonUp() ) only return true during the ONE frame that the mouse button was pressed (or released).

    • @lora6938
      @lora6938 3 года назад

      @@thesenpaicode Wow, how much you wrote everything. Thank you very much! Now I will deal with it. ☺️

    • @lora6938
      @lora6938 3 года назад

      @@thesenpaicode This is what I really need to do looks like:
      ruclips.net/video/mckl24tEwYk/видео.html
      Only In 2d now
      And After 3d I will need 😏🙂

  • @itsgamingmoonlight3400
    @itsgamingmoonlight3400 5 лет назад

    i need a help , in the player move , i copy the playerPlatformerCotroller but didn't work , it's 2D btw