Torch.cs 1.14 KB
Newer Older
Ashley's avatar
Ashley committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
using UnityEngine;
using System.Collections;

[RequireComponent (typeof(Light))]
public class Torch : MonoBehaviour {

    private Light myLight;
    private SpriteRenderer currentSprite;
    private Sprite unlitTorch = Resources.Load("Unlit torch side view", typeof(Sprite)) as Sprite;
    private Sprite litTorch = Resources.Load("Lit torch side view", typeof(Sprite)) as Sprite;

    // Use this for initialization
    void Start () {
        myLight = GetComponent<Light>();
        currentSprite = this.GetComponent<SpriteRenderer>();
    }
	
	// Update is called once per frame
	void Update () {
	
	}

    void activateTorch()
    {
        //activate the light component
        if(!myLight.enabled)
        {
            myLight.enabled = true;
            currentSprite.sprite = litTorch;
        }

    }
    void deactivateTorch()
    {
        //deactivate the light component
        if(myLight.enabled)
        {
            myLight.enabled = false;
            currentSprite.sprite = unlitTorch;
        }
    }
42 43 44 45 46 47 48 49 50 51

    public void activate()
    {
        activateTorch();
    }

    public void deactivate()
    {
        deactivateTorch();
    }
Ashley's avatar
Ashley committed
52
}