Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Changing a shader's offset value through scripting!

Discussion in 'Scripting' started by SP-Designs, Dec 11, 2016.

  1. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    Hello there,i am building a game and i am using a skybox asset from the unity asset store.I made a trigger object which i want to change the skybox's day to night cycle(that means it's offset value).However i cannot figure out how to do that through scripting.I tried using something like:
    renderer.material.SetFloat("_OFFSET", myOffset); but i didn't make it.Any ideas?Here's an image of the object:
    upload_2016-12-11_19-19-16.png :
     
  2. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    967
    material.SetFloat and friends would definitely be the way to achieve this, are you sure it is named _OFFSET in the shader? Are you certain you have a reference to the correct material?
     
  3. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    no and that's part of the problem....this skybox is an asset so i do not know what the shader's name is so i can make the reference :(....
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    in that inspector, click on the little cog for the shader and choose "edit shader" it should list all the attributes by their names.
     
  5. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    Only a text property is shown Capture.JPG
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  7. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    this was really helpful as far as figuring out the way but i am having an issue...this code alters the offset everytime the update function is called and sets the offset's value between two values but i want it to happen only once and use only one value.