Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 aksh2143 · Aug 21, 2015 at 10:28 AM · cameracolorlerpbackgroundchange color

How to randomly chenge camerabackground color every 5 seconds?

I want to change camera background color randomly from 50 to 200 every 5 seconds. How to do that? i am using below scrip but its not working.

public class Camera_cript : MonoBehaviour { Color bgcolor = Color.white; Color current = Color.black; Camera camera; public float duration = 3.0F;

 // Use this for initialization
 void Start () 
 {
     camera = GetComponent<Camera> ();

 }

 void Update () 
 {
     float t = Mathf.PingPong(Time.time, duration) / duration;
     camera.backgroundColor = Color.Lerp(current,bgcolor,0.5f);
 }

}

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

1 Reply

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

Answer by Ekta-Mehta-D · Aug 21, 2015 at 10:29 AM

Have you set camera clearFlags ?

Add this line of code in Start() :

 camera.clearFlags = CameraClearFlags.SolidColor;

For every 5 seconds :

 private float nextActionTime = 0.0f; public float period = 0.1f;
 
 void Update () 
 { 
      if (Time.time > nextActionTime ) 
      { 
            nextActionTime = Time.time + period; 
           // execute block of code here 
      } 
 }







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 aksh2143 · Aug 24, 2015 at 11:25 AM 0
Share

after working for few hours as i am just 20 days old to unity, i've come to this code below. Its working just fine as 99% i wanted it to. Thank you for your support miss. :)

using UnityEngine; using System.Collections;

public class Camera_cript : $$anonymous$$onoBehaviour { Color bgcolor; Color current;

 float duration = 1.0f;
 float t = 0.0f;
 float smoothnes = 0.02f;
 float increment = 0.02f;

public Camera camera1;

public void Start () {

     StartCoroutine (Change_color());

 
 }
 
 IEnumerator Change_color()
 {


     current = bgcolor; 
     bgcolor = new Color (Random.value, Random.value, Random.value);


     while (t < 2) 
     {

         camera1.backgroundColor = Color.Lerp (current, bgcolor, t);
         t += increment;
         yield return new WaitForSeconds (increment);
     }

     t = 0.0f;
     current = bgcolor;
     yield return new WaitForSeconds (Random.Range (3,6));

     StartCoroutine (Change_color());
 }

}

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Randomly Transition Camera Background Color? 2 Answers

C# Randomize Background.Color Issues 1 Answer

How do I loop a Color32.Lerp? 3 Answers

How can I create a gradient color background for my game, without using skybox? 2 Answers

HSV to RGB 1 Answer


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