How to Change fogcolor with script


#1

how to change fog color with script ?


#2

If you’re using the Editor you can hover over most attributes and it gives you a link straight to the API reference.
image

The API for fogColor shows it’s part of pc.Scene, which you can access through this.app.scene.

So to change the color of the scene you can do:
this.app.scene.fogColor = new pc.Color(r, g, b, a);


#3

this.app.scene.fogColor = new pc.Color(246, 227, 14, 1);
07%20PM
i tried with this code , play canvas editor shows perfect ,but while game running time shows full white color.


#4

pc.Color accepts float RGBA values ranging from 0…1 only. Bit confusing, I know. But you can simply divide your current values by 255 to get the float value. So you would do

this.app.scene.fogColor = new pc.Color(0.964, 0.89, 0.054, 1);

instead.


#5

thank you , working fine…