unity3d-2dtools

How to animate 2D clouds in Unity3D?


I have 2D game and cloud sprites. I need to animate it. To clouds generate randomly e.g. in the left edge of the screen and move to the right edge of the screen. Clouds count must variate from 1 to 4 that can be visible on the screen simultaneously.
How can I do it? Just what do I need to use (write own script or Unity3D has a some tools already?


Solution

  • Here is a step by step guide to create randomly moving clouds in Unity

    1. Create a prefab for the cloud sprite.
    2. Create a new C# Script named CloudScript and Attach it to to the cloud prefab.
    3. Add the code in this paste bin to the C# Script http://pastebin.com/iX41mDui
    4. Create an empty object in the scene and name it CloudManager
    5. Add the code in this paste bin to the C# Script http://pastebin.com/s5nYdwaV
    6. Set the public values for both scripts through inspector, based on preferences. For recommended values look at comments in code.

    After this the script should work and make the clouds move across the screen at random heights and random speeds. All the comments in the code should pretty much explain to you how the whole thing works.

    Just in case you need it, here's an example project with all the code in action https://www.dropbox.com/s/728v8ilzcvwff6e/RandomCloudMovementProject.unitypackage?dl=0