Unity | 'gameobject.renderer.material.color' in version 5.x

3.1k views Asked by At

I want to make a portion of the gameObject(guiTexture or sprite) as transparent color like "SpriteMask" which is in asset store. https://www.assetstore.unity3d.com/kr/#!/content/27642

Let me explain in more detail. For example, there are two gameObject in the scene. One is the background of the scene and the other one is just empty gameObject which can move when i drag it. The portion that gameObject is located of background should be made transparent simultaneously.

First, I tried it to use 'rendere.material.color.a' but it's deprecated in Unity version 5.x. Now I have no idea.

Below is all i want to do. https://www.drupal.org/files/project-images/Manual-Crop.jpg

Does anyone have good idea? How can i make it in simple way. Please give any idea. Thank you.

2

There are 2 answers

0
maraaaaaaaa On BEST ANSWER

Make a global variable

MeshRenderer renderer;

Start()
{
    renderer = gameObject.GetComponent<MeshRenderer>() as MeshRenderer;
}

now you can use renderer!

0
iSkore On

Update for 5.3.0f4 :

public GameObject mainObj;

void Start () {
    mainObj.GetComponent<MeshRenderer> ().material.color.a = 1.0f;
}