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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Accessing Parts of other Scripts/Components

Discussion in 'Scripting' started by DomDomDom, Apr 28, 2015.

  1. DomDomDom

    DomDomDom

    Joined:
    Jan 21, 2015
    Posts:
    43
    I apologize if this is an elementary question, but I can't seem to figure it out on my own. Below is a picture of the AmbientLight I'm working on and the SkyPane GameObject.



    What I'd like to do is change the alpha of the color in the Light Sprite script (used more than once on other game objects) from the TimeOfDayChnages script. I'd like that to also correlate that to the Time of Day which is controlled on my Sky Script. e.g. Time Of Day = 12 then color.alpha is 200. Or something to this nature. I know I'll need to do a little bit of math to get that conversion working properly.

    Any help would be appreciated!
    Dom
     
  2. Gnatty

    Gnatty

    Joined:
    May 17, 2012
    Posts:
    77
  3. DomDomDom

    DomDomDom

    Joined:
    Jan 21, 2015
    Posts:
    43
    Thank you! I'll see where I get after class today.
     
  4. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Check out my youtube video on GetComponent for additional understanding
     
  5. DomDomDom

    DomDomDom

    Joined:
    Jan 21, 2015
    Posts:
    43
    Thank you guys for all of your help!

    I looked into the code some more and I've been trying to figure out how to get the color variable from CustomSprite script (which is inherited into LightSprite) using getComponent into my TimeOfDayChanges script. I think I have to inherent it as well right? But then doesn't that run into the issue of changing the color of all the light objects in the scene? I only want my AmbientLight object to be changed... I'm not too sure how to approach this problem.