The wonderful weather settings can breathe life into your game. Yahaha Studio inherently supports the rapid configuration of the Weather System, including but not limited to various weather effects, post-processing, visibility and so on.
In Yahaha Studio → Scene Explorer → Environment → Weather, weather-related settings can be easily adjusted in the inspector panel.
Through configuring the settings, you can endow your game world in ideal weather conditions, like a bright afternoon in summer or a snowy evening in winter.
Nevertheless, there are moments when you wish for the weather to transform as the game progresses to enrich the gameplay and content. By integrating the weather API and event triggers, this desired effect can be accomplished!
First of all, let’s create a new empty object:
And we can rename it to “Weather Controller.”
Then, at the right corner of the inspector panel, Add script → New Lua script. This will bring us to the script editing IDE, which should be VS Code, defaultly.
In the script, define the weather system and invoke Yahaha Weather System API by writing down this line:
local weatherSystem = require("com.yahaha.sdk.graphics.WeatherUtils")
Then, call the API properties you want to adjust in the game and assign them corresponding values.
For the detailed API reference, please see the Weather API part in this article: [Lua API Updates] Introducing SkySystem, WeatherSystem, and PostProcess in Horror Game Kit 1.5!
For example, I changed the season to winter and let it snow when the game starts. Also, the time is at night.
After the game starts, the world is snowing and at night.
To better implement the occasions and logic of the weather change in the game, we can use Event Trigger to control the activation of the weather controller object.
In this example below, I will show you how to achieve a simple trigger event to control the weather.
I set up a trigger zone and event trigger logic so that when the player enters the zone, the weather controller object will be activated.
Since all the weather-changing logic is inside the function OnStart, the weather will change right after the object is activated.
Finally, make sure to hide the object before starting the game so that the weather will be changed only after the player interacts with the scene.
Let’s enter the play mode and test it out:
As the video shown above, the world is initially sunny and in daytime; after the player enters the center area, which is the zone we set up earlier, the world starts snowing and the night comes.
Looking forward to your wonderful games with the use of event trigger to adjust weather!