Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MithosAnnar · Mar 29, 2012 at 01:01 PM · sizeprocedural generation

How Do I Procedurally Generate Clouds ?

Hello Community!

I am giving procedural generation a crack. the goal is to instantiate planes (clouds) in a random area on screen.

In my case 0 - 480 on the x - axis, and 0 - 360 on the y - axis.

The script i'm using is this.

Script.js:

 #pragma strict
 
 var blueCloud : GameObject;
 var orangeCloud : GameObject;
 
 var cloudChance : int;
 
 var cloudPosition : Vector3;
 
 var cloudX : float;
 
 var cloudY : float;
 
 function Start () {
 
    cloudChance = Random.Range (1, 3);
    
 if (cloudChance == 1) {
 
    cloudX = Random.Range(0, 4.8);
    cloudY = Random.Range(0, 3.2);
 
    cloudPosition = Vector3(cloudX, cloudY, - 0.2);
    
    Instantiate (redCloud, cloudPosition, transform.rotation);
    
 }
 
 if (cloudChance == 2) {
 
    cloudX = Random.Range(0, 4.8);
    cloudY = Random.Range(0, 3.2);
 
    cloudPosition = Vector3(cloudX, cloudY, - 0.2);
    Instantiate (orangeCloud, cloudPosition, transform.rotation);
    
 }
 
 if (cloudChance == 3) {
 
    cloudX = Random.Range(0, 4.8);
    cloudY = Random.Range(0, 3.2);
 
    cloudPosition = Vector3(cloudX, cloudY, - 0.2);
    
    Instantiate (blueCloud, cloudPosition, transform.rotation);
    
 }
 
 }

But it only Instantiates the plane (cloud) randomly in the top right part of the screen (never behind or underneath the player).

Thanks for the interest so far!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Mar 29, 2012 at 01:20 PM 0
Share

Are your clouds geometry at the origo of the prefab root?

avatar image Kryptos · Mar 29, 2012 at 03:47 PM 0
Share

You are setting world coordinates, not screen coordinates. That's why.

avatar image MithosAnnar · Mar 30, 2012 at 12:18 PM 0
Share

@Statement: It's a plane with a GUITexture, so I'm not sure.

@$$anonymous$$ryptos: world and screen Co-ordinates aren't making any difference.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Mar 30, 2012 at 12:56 PM

The position property in GUIText and GUITexture is in viewport coordinates: 0,0 is lower left, 1,1 is top right. You must specify valid x and y coordinates (between 0 and 1). The z coordinate sets its depth relative to other GUIText or GUITexture objects (higher z appears over the others). If the GUI element is a child of another object, you must set its position after the instantiation; if the parent object moves, you must set the gui position each Update (any small parent movement shifts the gui object out of screen).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MithosAnnar · Apr 02, 2012 at 03:47 PM 0
Share

@AldoNaletto: Thank you!

sorry it's taken me so long to reply. I just thought i'd mention that I am using decimals because regular co-ordinates aren't working (4.8 ins$$anonymous$$d of 480 and 3.6 ins$$anonymous$$d of 360, no idea why!).

I can't seem to spawn the cloud randomly on the whole screen, with iphone screen resolution.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Icon (object) always faces camera, stays same size and can be seen through all other things. How to? 3 Answers

How to call animations in JS 1 Answer

Access JS From C# 1 Answer

wrong localScale on instantiated object unity 0 Answers

Procedural Generation generating infinitely? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges