Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Yassassin07 · Oct 26, 2016 at 04:39 PM · gameobjectlightinglightgameobjectsglow

How to make a game object light up only when its clicked on

Hi guys, so basically I got 4 game objects and i want them to light up only when they are clicked on. How do i do this please help.

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
0
Best Answer

Answer by Jessespike · Oct 26, 2016 at 05:38 PM

You can use OnMouseDown for clicks. Not sure what you mean by "light up"

 void OnMouseDown() {
     GetComponent<Renderer>().material.color = Color.green;
 }
Comment
Add comment · Show 3 · 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 nathanthesnooper · Oct 26, 2016 at 10:19 PM 0
Share

Ins$$anonymous$$d of GetComponent<Renderer>().material.color, use GetComponent<Renderer>().material and set that as 2 different materials with different tints.

avatar image Yassassin07 · Oct 28, 2016 at 04:53 PM 0
Share

Thank you for commenting @jessespike . What I mean by light up, for example if I have a cube as a game object and its green, I would want it to go to a bright green when I click on it then go back a to its normal color .

avatar image nathanthesnooper · Oct 30, 2016 at 01:40 AM 0
Share

Use renderer.material for this. $$anonymous$$ake 2 materials with different tints. Use them accordingly. (Set the two materials in your script using public $$anonymous$$aterial material1;) and set your objects GetComponent().material

avatar image
0

Answer by tiggy02 · Oct 28, 2016 at 05:47 PM

You need to create a light component then use OnMouseDown to detect a click then use that to change if the light is enabled or not.

private Light light;

void Awake() { light = GetComponent(); }

void OnMouseDown() { light.enabled = !light.enabled; }

Comment
Add comment · Show 2 · 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 Yassassin07 · Oct 28, 2016 at 06:27 PM 0
Share

Hi @tiggy02 I used your code but however keep getting an error when used. The error message is "Assets/Lightup.cs(19,1): error CS8025: Parsing error" I have copied and pasted the code down below can you please help.

using UnityEngine; using System.Collections;

public class Lightup : $$anonymous$$onoBehaviour {

private Light light;

void Awake() { light = GetComponent (); } void On$$anonymous$$ouseDown(){ light.enabled = !light.enabled; }

 }

}

avatar image tiggy02 · Oct 30, 2016 at 12:44 AM 0
Share

Hello @Yassassin07, sorry my code was never meant to be copy pasted. It was meant for you to look at then be able to learn, replicate, and change the code to conform to your needs. But if you really need a copy pas$$anonymous$$ble code here it is.

 private Light light;

 void Awake()
 {
     light = GetComponent<Light>();
 }

 void On$$anonymous$$ouseDown()
 {
     light.enabled = !light.enabled;
 }

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

Ammount of Light received by a GameObject 1 Answer

How to detect if a GameObject is hit by a Spotlight 4 Answers

I need help with directional light 1 Answer

How to make a GameObject not hittable by shadows ? 2 Answers

Advanced Lighting 1 Answer


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