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

Instantiate Gameobject Based On Texture alpha Value

Discussion in 'Scripting' started by Utopien, May 14, 2019.

  1. Utopien

    Utopien

    Joined:
    Feb 15, 2016
    Posts:
    46
    hello Community!

    i trying to make planet clouds and i would like to spawn the cloud object based on alpha value of an ghost sphere witch the textute will be apply on
    i am not really acustuom on textures so any help would be great thanks .....
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    You can use the .GetPixel() call to read the pixel on a texture:

    https://docs.unity3d.com/ScriptReference/Texture2D.GetPixel.html

    It returns a Color object, which contains the pixel alpha.

    ALSO: be sure you import your Texture2D with ReadWriteEnabled, and also make sure the alpha channel is being imported too, rather than ignored.
     
    Utopien likes this.
  3. Utopien

    Utopien

    Joined:
    Feb 15, 2016
    Posts:
    46


    thanks you that made my day
     
    Kurt-Dekker likes this.