Help with a Script.

Hello everyone, i seek your help. :c

I’m using this script (It’s for a torch, this script controls the animation of the fire, the intensity of the light, etc… (And no, this script is not mine, i’m using the script of this asset → Unity Asset Store - The Best Assets for Game Making, for personal use, i don’t try to steal it or make some kind of copy, i just want to learn how to do something)).

Name of the script: Torchelight.cs

using UnityEngine;
using System.Collections;

public class Torchelight : MonoBehaviour {
	
	public GameObject TorchLight;
	public GameObject MainFlame;
	public GameObject BaseFlame;
	public GameObject Etincelles;
	public GameObject Fumee;
	public float MaxLightIntensity;
	public float IntensityLight;
	

	void Start () {
		TorchLight.light.intensity=IntensityLight;
		MainFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*20f;
		BaseFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*15f;	
		Etincelles.GetComponent<ParticleSystem>().emissionRate=IntensityLight*7f;
		Fumee.GetComponent<ParticleSystem>().emissionRate=IntensityLight*12f;
	}
	

	void Update () {
		if (IntensityLight<0) IntensityLight=0;
		if (IntensityLight>MaxLightIntensity) IntensityLight=MaxLightIntensity;		

		TorchLight.light.intensity=IntensityLight/2f+Mathf.Lerp(IntensityLight-0.1f,IntensityLight+0.1f,Mathf.Cos(Time.time*30));

		TorchLight.light.color=new Color(Mathf.Min(IntensityLight/1.5f,1f),Mathf.Min(IntensityLight/2f,1f),0f);
		MainFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*20f;
		BaseFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*15f;
		Etincelles.GetComponent<ParticleSystem>().emissionRate=IntensityLight*7f;
		Fumee.GetComponent<ParticleSystem>().emissionRate=IntensityLight*12f;		

	}
}

Okey, now… What i want to do, is to put this “torch” in my scene, with the script disabled, so the player can enable it "pressing “E”. How i’m supossed to do that? I’m asking here because i really suck at C# and JS, i’ve watched videos and tutorials and i still don’t get it.

I tried using something like this at the end o the code, but it didn’t work. :frowning:

	function Update (){

	if (Input.GetKeyDown("e")) {
	
		if (Torchelight.enabled == false)
			Torchelight.enabled = true;
			else
			
			Torchetlight.enabled = true;
			}
}

Thanks for reading. (and i apologize for my english, it really sucks. :c )

Are you defining two Update functions? I think it will only call one of them.

The other point is that if it’s not enabled it won’t call Update.

Or is it that you have this Update on a different component than Torchelight, and all it does is turn Torchelight on and off. Which would address both my points above and your problem is something else.

You want to call TorcheLight.SetActive (bool) instead of .enabled

You’ll likely need to do the same with most of the other GameObjects in that script.