Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Flashlight On and Off Unity C# Script

Posted on January 27, 2021January 27, 2021 by Habibie

This simple script can be used for switching on and off a flashlight in Unity. Add the spotlight on your flashlight to the reference slot in the script.

Here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlashlightOnOff : MonoBehaviour
{
	
	public GameObject Flashlight;
	bool flashlightson;
	
    void Start()
    {
        flashlightson = false;
    }
	
	public void TurnOn(){
		Flashlight.SetActive(true);
		flashlightson = true;
	}
	
	public void TurnOff(){
		Flashlight.SetActive(false);
		flashlightson = false;
	}
	
	public void ToggleFlashlight(){
		if(flashlightson)
			TurnOff();
		else
			TurnOn();
	}
}

Watch the video to see how to use this script:

You can purchase the complete files as Unity Package here: https://creativeshop.ciihuy.com/product/on-off-switchable-flashlight-unity-package/

Post Views: 628
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme