Okay, so to start, I'm not super experienced with coding. I'm trying to make a script that makes a GameObject move from position 78.9 to position 0 if the light attached to the 'flashlight' variable is enabled and and it's intensity is greater than 0. Here's the script... Code (JavaScript): #pragma strict var UI : GameObject; var flashLight : Light; var fadeTime : float = 0.20763; function Start () { flashLight.GetComponent.<Light>().enabled = true; UI.transform.position.y = 78.9; } function Update () { if(flashLight.GetComponent.<Light>().enabled == true){ } if(flashLight.GetComponent.<Light>().intensity = > 0) { UI.transform.position.y -= 0.1 * Time.deltaTime / fadeTime; Debug.Log(flashLight.GetComponent.<Light>().intensity); } } I'm not sure what's wrong. It's probably something to do with the brackets, but I'm not sure.
Line 16. You are closing the contents if the conditional before the next part. So : Code (CSharp): if(flashLight.GetComponent.<Light>().enabled == true){ } if(flashLight.GetComponent.<Light>().intensity = > 0) { UI.transform.position.y -= 0.1 * Time.deltaTime / fadeTime; Debug.Log(flashLight.GetComponent.<Light>().intensity); } should probably be: Code (CSharp): if(flashLight.GetComponent.<Light>().enabled == true) { if(flashLight.GetComponent.<Light>().intensity = > 0) { UI.transform.position.y -= 0.1 * Time.deltaTime / fadeTime; Debug.Log(flashLight.GetComponent.<Light>().intensity); } }
I still get the same errors. Code (JavaScript): #pragma strict var UI : GameObject; var flashLight : Light; var fadeTime : float = 0.20763; function Start () { flashLight.GetComponent.<Light>().enabled = true; UI.transform.position.y = 78.9; } function Update () { if(flashLight.GetComponent.<Light>().enabled == true) { if(flashLight.GetComponent.<Light>().intensity = > 0) { UI.transform.position.y -= 0.1 * Time.deltaTime / fadeTime; Debug.Log(flashLight.GetComponent.<Light>().intensity); } } } Here's what I get... Assets/Lighter UI.js(17,56): BCE0044: expecting ), found '='. Assets/Lighter UI.js(17,58): BCE0043: Unexpected token: >. Assets/Lighter UI.js(17,60): BCE0043: Unexpected token: 0.
The error indicates where the error is (a couple of lines off, presumably because you had some blank lines). on 14 you have : Code (CSharp): if(flashLight.GetComponent.<Light>().intensity = > 0) A conditional should be a comparison operation (see here). You have " = > " which pretty much means nothing to the interpretor, which is why it is throwing an error. I assume you want "greater than or equal to" Which would be ">=" (note, there are no spaces). Give that a try.
The script works, but for some reason, the position doesn't start at 78.9, but at 149.2419. Why? I changed >=0 to just >0 also. Code (JavaScript): #pragma strict var UI : GameObject; var flashLight : Light; var fadeTime : float = 0.20763; function Start () { flashLight.GetComponent.<Light>().enabled = true; UI.transform.position.y = 78.9; } function Update () { if(flashLight.GetComponent.<Light>().enabled == true) { if(flashLight.GetComponent.<Light>().intensity >0) { UI.transform.position.y -= 0.1 * Time.deltaTime / fadeTime; Debug.Log(flashLight.GetComponent.<Light>().intensity); } } }