Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Unnamed · May 07, 2012 at 09:53 PM · c#gameobjectmeshrendererflashlight

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Drakestar · May 07, 2012 at 10:49 PM

Get rid of the round brackets after true and false.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Unnamed · May 07, 2012 at 11:08 PM 0
Share

Wow. It worked. Thanks :)

avatar image Unnamed · May 07, 2012 at 11:10 PM 0
Share

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.

avatar image Drakestar · May 08, 2012 at 12:06 AM 0
Share

What line is 27? It's telling you that you're trying to interact with an object that doesn't actually exist.

avatar image Unnamed · May 08, 2012 at 04:12 PM 0
Share

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.

avatar image
0

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...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges