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 MMitchell2000 · Mar 05, 2017 at 03:31 PM · c#movement

How do I create a scrolling sky?

I have some clouds that I want to move across the sky. I'm wondering how to write a code that will move them from their starting position and then once they hit the end (essentially because there's only a certain amount of cloud prefabs I have in the scene) will loop continuously and smoothly. Can anyone help?

*In C#

Comment
Add comment · Show 2
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 LiloE · Mar 05, 2017 at 10:01 PM 0
Share

Is this 2D game?

avatar image MMitchell2000 · Mar 06, 2017 at 02:19 AM 0
Share

This is in a 3d game

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by nug700 · Mar 06, 2017 at 02:24 AM

You spawn the cloud prefab above the map, have a starting point marked, have the cloulds move at a specific rate across the sky. Once They reach beyond a certain point, you set their position to the starting point.

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
0

Answer by $$anonymous$$ · Mar 06, 2017 at 02:25 AM

sorry if this code has errors... i havent tested

 public Int Multiplyer;
 void Update()
 {
 gameObject.GetComponent<Transform>().Position += Vector3.up * multiplyer
 }

change the vector3 to whatever you might need... like Vector3.Down or left or whatever.. Attach this to the cloud

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 nug700 · Mar 06, 2017 at 02:27 AM 0
Share

remember to multiply it by Time.deltatime, and you don't need to do gameObject.GetComponent<Transform>().Position every frame, just do transform.position, and $$anonymous$$ultiplyer would work better as a float.

avatar image
0

Answer by James2Games · Mar 06, 2017 at 05:00 AM

Here is something I wrote a while back that will spawn randomly sized clouds with random speed. Will need a prefab of the cloud and they will spawn around the CloudMaker

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CloudMaker : MonoBehaviour
 {
     public Cloud cloudTemplate;
 
     public Vector2 spawnHeight = new Vector2(3, 4);
     public float SpawnFrequency = 2;
     public float SpawnWidth = 200;
 
     private float lastSpawn = 0;
 
     // Update is called once per frame
     void FixedUpdate ()
     {
         if (lastSpawn >= SpawnFrequency)
         {
             var cloud = Instantiate(cloudTemplate, transform, false);
             cloud.Initialize();
 
 
             var y = Random.Range(spawnHeight.x, spawnHeight.y);
             var x = SpawnWidth / 2 * cloud.MoveDirection.x;
             var z = SpawnWidth / 2 * cloud.MoveDirection.z;
             cloud.transform.position = new Vector3(x, y, cloud.transform.position.z);
 
             lastSpawn = 0;
         }
         else
         {
             lastSpawn += Time.fixedDeltaTime;
         }
 
     }
 }

Attach this to the Cloud Prefab

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Cloud : MonoBehaviour
 {
     public Vector3 MoveDirection { get { return m_moveDirection; } }
 
     public Vector2 ScaleRange = new Vector2(0.25f, 1);
     public Vector2 SpeedRange = new Vector2(0.025f, 0.05f);
 
     
     public float MaxLife = 3;
 
     private Vector3 m_moveDirection = Vector2.zero;
     private float life;
     private float moveSpeed;
     
     public void Initialize()
     {
         // Randomzie speed and scale
         m_moveDirection = new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f));
         moveSpeed = Random.Range(SpeedRange.x, SpeedRange.y);
 
         float scale = Random.Range(ScaleRange.x, ScaleRange.y);
         transform.localScale = new Vector2(scale, scale);
     }
 
     IEnumerator Start()
     {
         yield return new WaitForSeconds(MaxLife);
         Destroy(gameObject);
     }
 
     void FixedUpdate ()
     {
         Vector3 move = m_moveDirection * moveSpeed;
         transform.position += move;
     }
 }
 
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
0

Answer by hxg946470289 · Mar 06, 2017 at 10:01 AM

using UnityEngine; using System.Collections;

/// /// 天空盒子的控制 /// public class SkyBoxController : MonoBehaviour { [SerializeField] private Material[] skyBoxMaterials;

 /// <summary>
 /// 当前天空盒子的索引
 /// </summary>
 private int skyBoxIndex = 0;

 /// <summary>
 /// 是否从暗到量
 /// </summary>
 private bool isToLight = true;

 /// <summary>
 /// 当前天空盒子的亮度
 /// </summary>
 private float currentLight = 1;

 /// <summary>
 /// 天空盒子的最小亮度
 /// </summary>
 [SerializeField]
 private float minLight = 1;

 /// <summary>
 /// 天空盒子的最大亮度
 /// </summary>
 [SerializeField]
 private float maxLight = 4;

 /// <summary>
 /// 天空盒子亮度的变化速度
 /// </summary>
 [SerializeField]
 private float changeSpeed = 0.01f;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update ()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         ChangeSkyBox();
     }

     ChangeSkyBoxArgs();

 }

 /// <summary>
 /// 改变当前天空盒子
 /// </summary>
 private void ChangeSkyBox()
 {
     skyBoxIndex++;
     if (skyBoxIndex > 3)
         skyBoxIndex = 0;
     RenderSettings.skybox = skyBoxMaterials[skyBoxIndex];
     RenderSettings.skybox.SetFloat("_Rotation", 0);
 }

 /// <summary>
 /// 改变天空盒子的参数
 /// </summary>
 private void ChangeSkyBoxArgs()
 {
     if (isToLight)
     {
         currentLight += changeSpeed;
         if (currentLight > maxLight)
             isToLight = false;
         RenderSettings.skybox.SetFloat("_Exposure", currentLight);
     }

     if (!isToLight)
     {
         currentLight -= changeSpeed;
         if (currentLight < minLight)
             isToLight = true;
         RenderSettings.skybox.SetFloat("_Exposure", currentLight);
     }

     float value = RenderSettings.skybox.GetFloat("_Rotation");
     RenderSettings.skybox.SetFloat("_Rotation", value + 0.006f);
 }


}

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

10 People are following this question.

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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to use Android Accelerometer(Left and right tilt) to turn a sphere object and camera in that direction? 1 Answer

How to make an object move to another object's location in a 2d game? 2 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