- Home /
How to enable disable items effects with key with best way?
I am working on FPS game and i have camp fire script how can i lit this campfire when i want. for example when character collide with CampFireTrigger "Set Fire: E" or just limited time for example 5 minutes because it looks so silly when firing all day and night. CampFire have child under it for example light, particles, smoke, flame i want to disable them with one key when i collide CampFireTrigger or with the time thing. this is the script.What i need to add it?
#pragma strict
private var drawGUI = false;
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
drawGUI = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
drawGUI = false;
}
}
function OnGUI ()
{
if (drawGUI == true)
{
GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Set Fire : E");
}
}
Answer by felixfors · Jan 06, 2016 at 05:24 PM
private bool drawGUI = false;
private bool active = false;
private float timer;
//How long the fire will be active
public float timerMax;
//apply fire Object here
public GameObject fireObject;
void OnTriggerEnter (Collider theCollider)
{
if (theCollider.tag == "Player")
{
drawGUI = true;
}
}
void OnTriggerExit (Collider theCollider)
{
if (theCollider.tag == "Player")
{
drawGUI = false;
}
}
void Update()
{
if(drawGUI && Input.GetKey(KeyCode.E))
{
active = !active;
}
if(active)
{
fireObject.SetActive(true);
timer +=Time.deltaTime;
if(timer >=timerMax)
{
active = false;
}
}
else
{
fireObject.SetActive(false);
timer = 0;
}
}
void OnGUI ()
{
if (drawGUI == true)
{
GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Set Fire : E");
}
}
Can you add some information i couldn't run it :( i am sorry .
I didnt code it so you can copy and past it, but if you have any sort of program$$anonymous$$g knowledge you should be able to see what to do, but give me a $$anonymous$$ and I will post the complete code for you
Assets/SetFireC.cs(2,20): error CS0116: A namespace can only contain types and namespace declarations
i take this error is this code C ? i can wait thank you very much
no same error
Blockquote
A namespace can only contain types and namespace declarations
Your answer
Follow this Question
Related Questions
Importing Scene with Multiple Animated Objects (Blender->Unity) 0 Answers
Possible to disable or hide an entire layer of animations? 1 Answer
How do I enable and disable animation in the animator controller by keys in unity3d 1 Answer
Animation Loop Disable? (WrapMode) 0 Answers
Animation cannot be disabled. 1 Answer