- Home /
Turning off renderer in other game object (C#)
Hi, I just took a tutorial on making a flashlight and it's pretty much done except I want it to disappear when it's off and appear when it's turned on. I have pretty much done this too, but since I don't know much of either scripts except for how they work and I am still learning javascript. I just have one compiler error and it uses terms I don't know of.
Here is the compiler error.
Assets/Game Project/Scripts/flashlight.cs(20,59): error CS0119: Expression denotes a value', where a
method group' was expected
Here is the script:
using UnityEngine;
using System.Collections;
public class flashlight : MonoBehaviour {
private bool FlashlightOn = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Flashlight") && FlashlightOn == false) {
FlashlightOn = true;
light.intensity = 1;
MeshRenderer otherScript = GetComponent<MeshRenderer>();
otherScript.renderer.enabled = true();
}
else if (Input.GetButtonDown("Flashlight") && FlashlightOn == true) {
FlashlightOn = false;
light.intensity = 0;
MeshRenderer otherScript = GetComponent<MeshRenderer>();
otherScript.renderer.enabled = false();
}
}
}
I know that it has to do with these lines (I think)
otherScript.renderer.enabled = false();
otherScript.renderer.enabled = true();
What do I correct?
Answer by Drakestar · May 07, 2012 at 10:49 PM
Get rid of the round brackets after true and false.
But now I am getting a different error, it still compiles but it prevents the script from working.
NullReferenceException: Object reference not set to an instance of an object flashlight.Update () (at Assets/Game Project/Scripts/flashlight.cs:27)
It appeared while I was testing it out.
What line is 27? It's telling you that you're trying to interact with an object that doesn't actually exist.
otherScript.renderer.enabled = false;
It also says the same for the other one: otherScript.renderer.enabled = true;
The script is attatched to the spotlight which is a child of the actual flashlight object, which is a child of the main camera which is a child of the first person controller, just so you know.
Answer by gjf · May 08, 2012 at 02:39 AM
at first glance, "true();" should just be "true;".
similarly "false();" should be "false;" - it's not a function.
the error message is telling you that...
Your answer
Follow this Question
Related Questions
Game object with animations 0 Answers
How to highlight only one face of a Cube from script? 0 Answers
Disable any objects through 1 script 1 Answer
How do I assign a renderer to a game object? 1 Answer
Extents of a Compound GameObject (C#) 2 Answers