Created
January 28, 2014 17:46
-
-
Save Problematic/8672511 to your computer and use it in GitHub Desktop.
Code used in "Creating a Flashlight GameObject in Unity3D" (https://www.youtube.com/watch?v=uPLahFRlmVA)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| [RequireComponent(typeof(Light))] | |
| public class Flashlight : MonoBehaviour { | |
| public GameObject source; | |
| public AudioClip toggleSound; | |
| Light _light; | |
| // Use this for initialization | |
| void Start () { | |
| _light = GetComponent<Light>(); | |
| } | |
| // Update is called once per frame | |
| void Update () { | |
| if(Input.GetButtonDown ("Flashlight")) { | |
| _light.enabled = !_light.enabled; | |
| AudioSource.PlayClipAtPoint(toggleSound, transform.position); | |
| } | |
| transform.Rotate(source.transform.rotation.eulerAngles - transform.rotation.eulerAngles); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment