c# - Fog Changing by position transform.position.y -


i need fog change 2 times once on level of y150 , second time on level y90. wanted set gameobject.transform.position.y function y150 y80 cant figure out how done.

thank here code far

// use initialization void start () {   }  bool isunderwater(){      return gameobject.transform.position.y < 150;     rendersettings.fog = true;     rendersettings.fogcolor = new color (0.15f, 0.35f, 0.40f, 0.5f);     rendersettings.fogdensity = 0.03f;  } bool isnotunderwater(){      return gameobject.transform.position.y < 90;     rendersettings.fog = true;     rendersettings.fogcolor = new color (0.8f, 0.4f, 0.2f, 0.5f);     rendersettings.fogdensity = 0.03f;  }    // update called once per frame void update () {      rendersettings.fog = isunderwater();     rendersettings.fog = isnotunderwater ();  } 

the 'return' statement in programming languages, including c#, exit function, returning given value. means following lines affect fog settings never run.

there bunch of different ways set code up, here's simple example:

void setfog() {     if(transform.position.y >= 150)     {         rendersettings.fog = true;         return;     }      if(transform.position.y >= 90)     {         rendersettings.fog = true;         rendersettings.fogcolor = new color (0.15f, 0.35f, 0.40f, 0.5f);         rendersettings.fogdensity = 0.03f;          return;     }      rendersettings.fog = true;     rendersettings.fogcolor = new color (0.8f, 0.4f, 0.2f, 0.5f);     rendersettings.fogdensity = 0.03f; }  void update() {     setfog(); } 

keep in mind simple solution, , not extensible or maintainable. may worth adding array of settings object can tweak in editor, 1 entry each of different heights.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -