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 wang3922 · Aug 20, 2015 at 10:07 PM · c#materialhighlightpinkhighlighting

Can't get highlight to work when mousing over object..

I have a grid of objects instantiated through a grid-making script. The script is attached to an empty gameobject in the scene.

Attached to each grid object (which appear as clones for some reason) is a script called "Highlight" which I'm trying to get to highlight each grid object green as I mouse over them. All that happens is the objects turn pink when instantiated and that's all. When I hover over them nothing happens either. I can assign the correct material to "normalColor" in the inspector which gets rid of the pink, but how do I get it to do this automatically? And how do I get my highlight working? Thanks! Total noob here.

 using UnityEngine;
 using System.Collections;
 
 public class Highlight : MonoBehaviour {
 
     public Renderer rend;
     public Material normalColor;
     public Color highlightColor;
 
     void Start () {
         rend = this.GetComponent<Renderer>();
         rend.material = normalColor;
     }
     
     void Update () {
         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         RaycastHit hitInfo;
         if (Physics.Raycast (ray, out hitInfo, Mathf.Infinity)) {
             rend.material.color = highlightColor;
             Debug.Log ("moused over object");
         }
         else {
             rend.material = normalColor;
         }
     }
     
 //    void OnMouseOver () {
 //        //        Debug.Log (gameObject.name + " OnMouseOver");
 //        Debug.Log ("moused over object");
 //        rend.material.color = highlightColor;
 //    }
 //    
 //    void OnMouseExit () {
 //        //        Debug.Log (gameObject.name + " OnMouseOver");
 //        
 //        rend.material.color = normalColor;
 //    }
 
 }

alt text

alt text alt text

highlight-issue-inspector.jpg (200.8 kB)
highlight-issue-medium.jpg (197.8 kB)
Comment
Add comment · Show 3
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 wang3922 · Aug 20, 2015 at 09:40 PM 1
Share

Yep, Thank you! That totally solved the mouse over issue. Now I just have the pink material when not mousing over problem and an incorrect material when I am mousing over.. I'm pretty sure it's just a $$anonymous$$or scripting mistake.

Here's exactly what's happening:

If I drag a TrackJump$$anonymous$$edium prefab into the editor it's material "betterdirt1" looks correct. Variables in the inspector read:

Rend "None (Renderer)" Normal Color "None ($$anonymous$$aterial)" Highlight Color green that I want, now semi-transparent

Then I hit play, the "betterdirt1" material disappears from inspector, and my variables read:

Rend "TrackJump$$anonymous$$edium ($$anonymous$$esh Renderer)" Normal Color "None ($$anonymous$$aterial)" Highlight Color green that I want, now semi-transparent

When I mouse over the now-pink prefab in the scene it indeed turns green but doesn't show the material underneath (I have changed Highlight Color to mostly transparent green ins$$anonymous$$d of opaque like it was in the above images). When I mouse off it returns to pink. I'm trying to get the prefab to display with "betterdirt1" material all of the time, with a green highlight when moused over.

avatar image Positive7 · Aug 20, 2015 at 10:51 PM 1
Share

It's pink because you didn't assign "betterdirt1" to "Normal Color" in the Inspector

avatar image wang3922 · Aug 20, 2015 at 11:16 PM 0
Share

Sometimes I wonder about myself lol... Thank you. That solved everything.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How can i highlight objects with the mouse when the mouse cursor is moving over objects ? 1 Answer

Distribute terrain in zones 3 Answers

Need help with my script - Rollover change material and click change material 0 Answers

[Solved] Changing material through network PUN 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