Search Unity

Problem with transparence in quad

Discussion in '2D' started by xuturk, Nov 25, 2013.

  1. xuturk

    xuturk

    Joined:
    Nov 24, 2013
    Posts:
    7
    Hi.

    I have a scene in Unity 4.3 with a Sprite and a camera and i want make a fade effect, to do this, im creating by script a new Quad gameobject and modifying the position, the material and the alpha color of this material.

    The Script is:

    Code (csharp):
    1. void Start ()
    2.     {
    3.         pixel = GameObject.CreatePrimitive (PrimitiveType.Quad);
    4.         pixel.name = "pixel";
    5.  
    6.         float height = Camera.main.orthographicSize * 2.0f;
    7.         float width = height / Screen.height * Screen.width;
    8.         pixel.transform.localScale = new Vector3 (width, height, 1);
    9.         pixel.transform.position= new Vector3(pixel.transform.position.x,pixel.transform.position.y,-0.1f);
    10.  
    11.         color.a = 0.5f;
    12.         pixel.renderer.material = new Material(Shader.Find("Transparent/Diffuse"));
    13.         pixel.renderer.material.color = color;
    The result is:
    $Sin título.png

    The red background is the Quad and the transparence works but the Sprite is near to camera independently that the Quad position.

    somebody can help me?

    Thanks!