Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Trail renderer only on specific area

Discussion in 'UGUI & TextMesh Pro' started by elpuerco63, Nov 10, 2017.

  1. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    I have a trail renderer that allows me to draw with finger over a canvas image but am unable to stop the trail continuing outside of the canvas image, imagine drawing on a piece of paper and when your finger goes off the edge of the paper the drawing stops.

    I am trying like this with not much luck, can anyone help please?

    Code (csharp):
    1.  
    2. Ray mRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    3.  
    4.             float rayDistance;
    5.  
    6.             if (objPlane.Raycast (mRay, out rayDistance)) {
    7.                    
    8.                 if (rect.rect.Contains (Camera.main.WorldToViewportPoint (mRay.GetPoint (rayDistance)))) {
    9.  
    10.                     thisTrail.transform.position = mRay.GetPoint (rayDistance);
    11.                 }
    12.             }
    13.  
     
    Last edited: Nov 10, 2017
  2. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    Anyone? Is there no way to have a trail renderer only draw on a certain part of the screen?
     
  3. Jufin

    Jufin

    Joined:
    Nov 7, 2016
    Posts:
    1
    perhaps prevent your mouse from leaving the paper area?
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    elpuerco63 likes this.
  5. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271