Skip to content

Instantly share code, notes, and snippets.

@Problematic
Created January 28, 2014 17:46
Show Gist options
  • Select an option

  • Save Problematic/8672511 to your computer and use it in GitHub Desktop.

Select an option

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)
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