Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't modify the new _Rotation property of the 6 Sided Skybox shader

Discussion in 'Scripting' started by arcooke, Mar 5, 2015.

  1. arcooke

    arcooke

    Joined:
    Sep 1, 2014
    Posts:
    29
    I am very new to Unity, just picked up U5 yesterday.

    I am trying to set up a simple skybox rotation. My code is based on the documentation for Material.SetFloat

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SkyboxRotate : MonoBehaviour {
    5.  
    6.     public Renderer rend;
    7.     public float rot;
    8.  
    9.     void Start() {
    10.         rot = 0;
    11.         rend = GetComponent<Renderer>();
    12.         rend.material.shader = Shader.Find("Skybox/6 Sided");
    13.     }
    14.     void Update() {
    15.         rot = (rot + 5.0F) % 360;
    16.         rend.material.SetFloat("_Rotation", rot);
    17.         Debug.Log(rend.material.GetFloat("_Rotation")); // it appears to be working....
    18.     }
    19.  
    20. }
    When I print the value from GetFloat, it is indeed getting set, but nothing is visibly happening on the screen. Any idea why this is?

    Debug: http://i.imgur.com/cfdW6St.png

    My goal is to simulate this effect: http://i.imgur.com/e0gc6oZ.gifv
     
  2. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    i have another way to achieve it..

    add another camera.
    let that camera render skybox only
    add an animation to the camera (for instance, 360 degrees rotation)
    wrap it like loop.
     
  3. arcooke

    arcooke

    Joined:
    Sep 1, 2014
    Posts:
    29
    That's not a bad idea either. Still curious why this wont work though.

    "let that camera render skybox only"

    How do you do that? I don't see anything related in the camera's properties and Google isn't turning much up. Again I'm on day one of Unity so please excuse me if I'm missing something simple here.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I've played around with moving skyboxes before, the only reliable way I've found is to create a giant inverted cube and rotate that. Wont work if you need a small viewdistance camera
     
  5. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    arcooke ... is the "Camera Flags" option.. the rotating camera must to be set as Skybox..
    the Main Camera must be set to Don't Clear.

    I forgot something..
    set the depth of MainCamera as 1
    and the depth of skyboxCamera to 0

    this is the result:

     
  6. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    another example

     
  7. arcooke

    arcooke

    Joined:
    Sep 1, 2014
    Posts:
    29
    Nice thank you! I've set up my cameras now I am trying to figure out the animation system. Will let you know how it looks if I can get everything working.
     
    Last edited: Mar 5, 2015
    U7Games likes this.