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