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

Accessing and changing variables available on other objects

Discussion in 'Scripting' started by Archangel3d, Mar 4, 2010.

  1. Archangel3d

    Archangel3d

    Joined:
    Feb 12, 2010
    Posts:
    3
    I seem to be having problems having scripts affect objects they are not applied to. I'm sure once I get the solution it'll be a "palm to forehead" moment, but for now I'm rather stumped.

    Basically, I have an object (a dial) that rotates OnMouseDown. That works fine. However, I'd also like to control the Light (named Bulb01) in my scene with the same mouse click; increasing the intensity of the light with each click on the dial, for example.

    I also have an exposed variable in a script attached to Bulb01 (the light), which is a % of chance that the bulb is destroyed (burns out). I'd like to access this variable from the script on my dial, to be able to increase the variable's number each OnMouseDown (the variable in question starts at 0).

    Once I see how it's done, I'm sure I'll be able to work the rest of the stuff I need from there, but I'm still stuck at the "language barrier", so to speak.

    Thanks in advance!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  3. Archangel3d

    Archangel3d

    Joined:
    Feb 12, 2010
    Posts:
    3
    Oh dear, how embarrassing. My first post and I end up asking a quintessential "Read The Manual" question. My apologies, and thanks for the link!

    ... nothing to see here, move along :oops: