Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Getting all textCoords where objects collide

Discussion in 'Scripting' started by Fluzing, Jul 10, 2014.

  1. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Hi All,

    I am trying to alter a quad with a texture by using SetPixels. It works fine, but what I want to do now is at the start of a scene to make the pixels that an object touches black. I have no idea on how to do this.

    I have tried using SphereCast, OverlapSphere etc, but these only give me one collider or one contact point. Is there a way to get all the texture coordinates by casting?

    In short: I have a quad with a white texture. I want to paint part of it black by firing a sphere at it at the start of the scene. I want to use SetPixels for this.
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Just create the appropriate sprite. Add it to your atlas. Adjust the pixels, uv's accordingly. Just as you were before. You said you could use setPixels. Why not again?
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    If it's a sphere collider then can it be as simple as getting all the pixels in a radius around the contact point? Or are you looking for something more robust than that?
     
  4. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    How do I know how many pixels wide the sphere is?
     
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    If you know how big the radius is then you can add the radius to the world space position of the center of the collider and WorldToScreenPoint that new position.

    Alternately - add the radius to the center and raycast against your target from that new position.