- Home /
Question by
minimalkid1 · Nov 30, 2014 at 04:27 PM ·
actionactionsclickingdeffered
2 click - defferent actions
//Hello. i work in C# script!
using UnityEngine;
using System.Collections;
public class Torchelighte : MonoBehaviour {
public float IntensityLight;
//if i press 1 time click the torch light up
if (Input.GetButtonDown ("Fire1")) {
IntensityLight = 2;
}
//if i press 1 more time click the torch must don't light
if (Input.GetButtonDown ("Fire1") && IntensityLight == 2) {
IntensityLight = 0;
}
}
what i can do to make this work perfectly. if i press 1 time click the torch don't light up...If i put first command the torch light up but when i put the second command the torch don't light up... I need help fast. Thx.
Comment
Answer by YoungDeveloper · Nov 30, 2014 at 04:30 PM
I wouldn't compare floats like that, you could use bool to trigger or enum states.
private bool lightOn = false;
public float intensity = 0;
if (Input.GetButtonDown("Fire1")){
lightOn = !lightOn;
if(lightOn) intensity = 2f;
else intensity = 0f;
}
If your commenting on answer, use comment.
Checking question as answered also helps.
Your answer
Follow this Question
Related Questions
Action when clicking on something else 2 Answers
System.Action is not working for WebGL build 1 Answer
Unet - adding [Command] function to Action C# 0 Answers
When object clicked, make HUD apper 1 Answer
Problem with P.C. touchpad. 1 Answer