Search Unity

need help with flashlight script

Discussion in 'Scripting' started by yerp_1234567890, Jan 13, 2022.

  1. yerp_1234567890

    yerp_1234567890

    Joined:
    Dec 10, 2021
    Posts:
    3
    i am trying to make a game with a flashlight and the script i am using will say this variable is not assigned and when i add the variable it says it is already assigned. this is the code:
    using UnityEngine;
    using System.Collections;




    public class Flashlight_PRO : MonoBehaviour
    {
    [Space(10)]
    [SerializeField()] GameObject Lights; // all light effects and spotlight
    [SerializeField()] AudioSource switch_sound; // audio of the switcher
    [SerializeField()] ParticleSystem dust_particles; // dust particles



    private Light spotlight;
    private Material ambient_light_material;
    private Color ambient_mat_color;
    private bool is_enabled = false;

    // Use this for initialization
    void Start ()
    {
    // cache components
    spotlight = Lights.transform.Find ("Spotlight").GetComponent<Light> ();
    ambient_light_material = Lights.transform.Find ("ambient").GetComponent<Renderer> ().material;
    ambient_mat_color = ambient_light_material.GetColor ("_TintColor");
    }






    /// <summary>
    /// changes the intensivity of lights from 0 to 100.
    /// call this from other scripts.
    /// </summary>
    public void Change_Intensivity(float percentage)
    {
    percentage = Mathf.Clamp (percentage, 0, 100);


    spotlight.intensity = (8 * percentage) / 100;

    ambient_light_material.SetColor ("_TintColor", new Color(ambient_mat_color.r , ambient_mat_color.g , ambient_mat_color.b , percentage/2000));
    }
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Please use [ code ][ / code ] tags and tell us exactly what the error message is.