Help❓ Unity and Light with C# ... [HELP]

Posts 1–5 of 5 · Page 1 of 1
Unity and Light with C# ... [HELP][Solved !]
I tryed the same code (After I converted it to Java) to Java Code and it worked normally ... but after I used C# to do the same work it didn't worked I used this code for Java :
Code:
function Update () {
	
	if(Input.GetKeyDown(KeyCode.F)){
		if(light.enabled == true)
			light.enabled = false;
		else
			light.enabled = true;
			}
			}
And this for C# which didn't worked :
Code:
void Update () {
		if(Input.GetKey(KeyCode.F)){
			if(light.enabled = true){
				light.enabled = false;
			}
			else{
				Light.enabled = true;
			}
		}
	}
If you can help guys help ... Ah ... also I am a new member and I welcome myself to this beautiful forum
-------------
This Topic Has Been Solved ... thank you guys for help
if(light.enabled = true){

You missed a =, it needs to be == for comparing.

Also you can simplify the code to:
Code:
    void Update()
    {
        if (Input.GetKey(KeyCode.F))
        {
            light.enabled = !light.enabled;
        }
    }
You are right ... I forgot about the boolean logic ... but I repaired it and it keep sending me an error ... The Code I have now :
Code:
using UnityEngine;
using System.Collections;

public class flashing : MonoBehaviour {
	// Update is called once per frame
	void Update () {
		if(Input.GetKey(KeyCode.F)){
			if(light.enabled == true){
				light.enabled = false;
			}
			else{
				Light.enabled = true;
			}
		}
	}
	
}
And the error :


Edit :
I Did it ! Thank you dude you helped ... I thanked you
The method is
Code:
Input.GetKey
or
Code:
 Input.GetKeyDown
?
I am sorry ... the method is GetKeyDown ... isn't the same thing as an idea ? I mean generaly both of them doing the same thing except one little ... that GetKey is able to use the next code after it if only you stop holding the key ...
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us