Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Creating an outline on an object for onmousedown

Discussion in '2D' started by JeremyBTA, Aug 14, 2023.

  1. JeremyBTA

    JeremyBTA

    Joined:
    Jul 26, 2023
    Posts:
    4
    How could I do this? Do I need to purchase something from the asset store? I know how to highlight the whole object using the monobehavior.onmouseover() documentation but I am just trying to outline the border of it when the mouse button is clicked. Thank you!
     
  2. anilsayar

    anilsayar

    Joined:
    Oct 14, 2018
    Posts:
    14
    Hello,

    I believe that you are looking for something like in this video:
    How to make a 2D OUTLINE in Unity! - YouTube

    If it is, then set its thickness to zero. Then, inside MouseOver function, you should set thickness a decent number. Keep in mind that MouseOver function detects the objects only with collider.
     
  3. JeremyBTA

    JeremyBTA

    Joined:
    Jul 26, 2023
    Posts:
    4
    How would I go towards approaching this?
     
  4. anilsayar

    anilsayar

    Joined:
    Oct 14, 2018
    Posts:
    14
    - Complete the steps in the video. Play with the slider and see the outcome.
    - Add your character collider (2D).
    - Create a script and attach the character. It should outline the following:
    Code (CSharp):
    1. public class outline : monobehaviour
    2. {
    3.    private Material mat;
    4.  
    5.    void Start
    6.    {
    7.        mat = GetComponent<SpriteRenderer>.material.
    8.    }
    9.  
    10.   void OnMouseDown()
    11.   {
    12.       mat.SetFloat("Vector1_SA....", 0.05)
    13.      //What is this crazy name? Because he defines thickness value 's reference as this is (Check Sprite Outline Panel inside Shader Graph). You may simplify the name.
    14.     //Why 0.05? Because he sets the max value of slider 0.05
    15.   }
    16.  
    17.   void OnMouseUpAsButton() // or simply OnMouseUp()
    18.   {
    19.         mat.SetFloat"Vector1_SA....", 0)
    20.   }
    21. }
    So, this is supposed to outline the character when you pressed on it. It should go back to usual, when you release the button.