private var rend;
function Awake()
{
if (gameObject.GetComponent(TextMesh) != null)
rend = gameObject.GetComponent.<TextMesh>();
else if (gameObject.GetComponent(SpriteRenderer) != null)
rend = gameObject.GetComponent.<SpriteRenderer>();
}
Now if I want to use rend
rend.color.a = 0.5; // Gives an error: 'color' is not member of 'Object'
So I have to do it in this way:
(rend cast SpriteRenderer).color.a = 0.5; // if using SpriteRenderer
However, I have to do this maybe 100 times in my script and I have to always check which
type I’m using making all this pointless. The idea behind this is to use the same variable to change things regardless what type is placed to gameobject. So I could always use like rend.color.a, because both TextMesh and SpriteRenderer have color properties.