Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Lamp : MonoBehaviour
- {
- // set these up in the inspector
- // the spriteRenderers will be dragged in from the scene
- public SpriteRenderer lampSpriteRenderer, skySpriteRenderer;
- // these sprites are Assets, they should be dragged in from the project folder
- public Sprite lampOn, lampOff;
- public Sprite skyOn, skyOff;
- // have to add a boxcollider (or spherecollider) to this to make it actually clickable. set it to be a trigger (isTrigger checkbox)
- void OnMouseDown()
- {
- // if the lamp spriteRenderer (thing that renders the lamp onscreen) has the lampOn sprite, then ...
- if (lampSpriteRenderer.sprite == lampOn)
- {
- // we want ot set it off
- lampSpriteRenderer.sprite = lampOff;
- // and set the sky off too!
- skySpriteRenderer.sprite = skyOff;
- }
- // if the lamp spriteRenderer (thing that renders the lamp onscreen) is NOT showing the lampOn sprite, we can assume it's showing the lampOff sprite...
- else
- {
- // so turn the lamp on
- lampSpriteRenderer.sprite = lampOn;
- // and the sky too! :)
- skySpriteRenderer.sprite = skyOn;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement