• 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 Elliot123 · Jan 09, 2015 at 11:21 AM · tagshighlight

Highlight object script wont work

Im trying to toggle the renderer of the tagged objects accordingly on function Start and OnMouseEnter/OnMouseExit as well as the addhighlight/remove highlight function but im having no luck. Im new to code so any help would be much appreciated!

 // Attach to Main Camera
 // Add tag to objects you want to highlight
 // call functions to add/remove the highlight
  
 private var timer : float = 0.0;
 private var originalColor;
 var highlightMultiply = 1.50;
 var highlightTag = "OPSM";
 private var gos;
  
 function Start() {
     gos = GameObject.FindGameObjectsWithTag(highlightTag);
     if(gos) {
         originalColor = gos[0].renderer.material.color;
         renderer.enabled = false;
     }
 }
  
  function addHighlight() {
     timer += Time.deltaTime;
     if((timer != 0) == (gos)) {
         for(var go in gos) {   
             go.renderer.material.color.r = originalColor.r*highlightMultiply;
             go.renderer.material.color.g = originalColor.g*highlightMultiply;
             go.renderer.material.color.b = originalColor.b*highlightMultiply;
             go.renderer.material.color.b = go.renderer.material.color.b*highlightMultiply;
         }
     }
 }  
  
 function removeHighlight() {
     timer = 0.0;
     // Set color back to original
     if(gos) {
         yield new WaitForSeconds(0.1);
         for(var go in gos)
         {  
             go.renderer.material.color = originalColor;
         }
     }
 }
 
 function OnMouseEnter(){
 gos.renderer.enabled = true;
 addHighlight == true;
 
 }
 function OnMouseExit(){
 gos.renderer.enabled = false;
 removeHighlight == true;
 
 }
 

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Graham-Dunnett · Jan 09, 2015 at 11:26 AM

Well, where to start:

Line 6-9 appear to be missing types. I know JS lets you get away with this, but don't let it.

Line 13, gos is presumably meant to be an array, so check if it's length is more than zero.

Line 15, what renderer?

Line 21, how can you compare a boolean to an array?

Line 45/50 == means "is equal to", it's a test, not an assignment.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Two cameras and switching 2 Answers

Why doesn't this work? 1 Answer

How can i get a list of tags from the tag manager? 1 Answer

How to change the tag of one object, when another object is selected. 0 Answers

How do I make it so that I can attack more than 1 enemy? 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