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 vlknff · Apr 25, 2012 at 05:30 AM · skyboxrendersettings

Switching between skyboxes

Hi all, I am trying to switch between skyboxes in RenderSettings based on Random value but seems like my logic is not working properly. I am quite a beginner in coding.

any help would be great :)

var stars: Material; var sky: Material;

RenderSettings.skybox = stars;

function Update() {

     if ( Random.value > 0.5 )
     {
        if (RenderSettings.skybox == sky) 
        {
           RenderSettings.skybox = stars; 
        }
        else
        {
           RenderSettings.skybox == sky;
        }
   }    

}

Comment
Add comment · Show 1
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 venkspower · Apr 25, 2012 at 05:31 AM 0
Share

But where are you generating the random value?

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by BiG · Apr 25, 2012 at 09:54 AM

You've done a very little mistake, but this is relevant!!! Look at the double "=" in the following statement:

    else
    {
       RenderSettings.skybox == sky;
    }

Replace with:

    else
    {
       RenderSettings.skybox = sky;
    }

Double "=" is for a comparison, single "=" is for an assignment. But I think it was just a copy-&-paste error, since I see that you've understood this logic from the other lines.

EDIT: I also see that your code is inside an Update function, and it's executed every frame. Two problems about this: 1) it's computationally expensive for an operation of skybox changing 2) it's useless, because you couldn't have the time to see the changes, unless the same range of values is generated for a long time. Try this:

 var stars: Material;
 var sky: Material;
 
 RenderSettings.skybox = stars;
 
 function Start()  {
 
    while (true)
    {
       if ( Random.value > 0.5 )
       {
          if (RenderSettings.skybox == sky) 
          {
             RenderSettings.skybox = stars; 
          }
          else
          {
             RenderSettings.skybox = sky;
          }
       }  
    yield WaitForSeconds(1); //adjust the time between the possible change.
    }
 }
Comment
Add comment · Show 2 · 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 xjy9201 · Apr 03, 2015 at 10:26 AM 0
Share

if adding while(true) in Start function, i think the program will be crashed

avatar image BiG · Apr 03, 2015 at 10:44 AM 0
Share

@xjy9201 Uhm...NO.

avatar image
1

Answer by Kryptos · Apr 25, 2012 at 11:49 AM

This shader can be of some use: SkyboxBlended.

Comment
Add comment · 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
1

Answer by vlknff · Apr 25, 2012 at 10:50 PM

Thanks for the good explanation! Very helpful :)

you can see it working! Yey alt text

Comment
Add comment · 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

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

Lerp RenderSettings skybox 3 Answers

Black Artifacts in Skybox - Android/Quest 1 Answer

After adding a skybox in render settings, the water (advanced) I had previously setup is gone. Any Suggestions? 0 Answers

RenderSettings.skybox script edit does not work 1 Answer

Add Light Source to Sun in Environmental Lighting with Unity 5 by Script? 3 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