- Home /
Question by
ahmadfirdausabas · Aug 26, 2015 at 09:57 PM ·
get component
How to get Game object size and fade it.
Im trying to fade each game object , not the full screen. how to get the game object size and fade the game object ?
Comment
Answer by azmundai · Aug 27, 2015 at 02:17 AM
gameobject.transform.localscale
local scale is a Vector3, so
IEnumerator FadeGameObject(gameObject go){
float speed = 0.1f;
while(go.transform.localscale.x > 0.01){
go.transform.localscale = new Vector3(go.transform.localscale.x - speed, go.transform.localscale.y - speed, go.transform.localscale.z - speed);
yield return null;
}
// then turn the game object off
go.SetActive(false);
// OR destroy the game object, removing it from the scene completely.
Destroy(go);
}
To activate an IEnumerator use
StartCoroutine(FadeGameObject(myGameObject));
Your answer
Follow this Question
Related Questions
How to sort get components? 3 Answers
Get the color component from a raw image UI 1 Answer
null reference exception on get component 4 Answers
get collider component by raycast 0 Answers
how to create a custom type in C#? public Atype atype; 1 Answer