Search Unity

optimization questions

Discussion in 'Scripting' started by lesfundi, Feb 24, 2010.

  1. lesfundi

    lesfundi

    Joined:
    Jan 10, 2009
    Posts:
    628
    i have GUI in my scene, by default it is white. If I use this script below to set the color to red i think that would not be good because it is a function update, or would this be okay?


    function Update () {
    guiText.material.color = Color.red;
    }
     
  2. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    Well it seems okay but you could try checking the color and only changing it if its not already red.
    Code (csharp):
    1. function Update () {
    2. if(guiText.material.color!=Color.red)
    3. {
    4. guiText.material.color = Color.red;
    5. }
    6. }
     
  3. lesfundi

    lesfundi

    Joined:
    Jan 10, 2009
    Posts:
    628
    yes, but this script will be running also all the time? or not?

    would function Start to the trick?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Update runs every frame. Don't use Update unless you actually want something to happen every single frame.

    --Eric