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 /
  • Help Room /
avatar image
0
Question by tylerhouse999 · Sep 02, 2018 at 06:38 PM · not workingmouseclicktop

some 3d objects not responding to onMouseEnter and onMouseDown

I have a map made out of 3d objects and every one of them have the Node.cs script, in Node.cs the node changes color when onMouse enter and changes back when mouse Exit, for most of the nodes it works, but for the nodes at the top of the screen(about 20) it would not change color or Debug.Log() anything. There are a total of about 250 nodes in the screen and its all inside a GameObjects called Nodes witch has no collider or Rigidbody.

This is Node.cs:

 using UnityEngine;
 using UnityEngine.EventSystems;
 public class Node : MonoBehaviour {
 public Color hoverColor;

 public GameObject Turrent;
 private Renderer rend;
 // Use this for initialization

 public Vector3 positionOffset;
 private Color originalColor;
 public Color ErrorColor;
 private void Start()
 {
     
     rend = GetComponent<Renderer>();
     originalColor = rend.material.color;
 }


 public Vector3 GetBuildPosition()
 {
     return transform.position + positionOffset;
 }
 private void OnMouseDown()
 {
     if (EventSystem.current.IsPointerOverGameObject())
     {
         return;
     }
     if (!BuildManager.instace.canBuild)
     {
         return;
     }
     if (Turrent != null)
     {
         return;
     }
     BuildManager.instace.BuildTurrentOn(this);

 }

 void OnMouseEnter()
 {
     if (EventSystem.current.IsPointerOverGameObject())
     {
         return;
     }
     if (!BuildManager.instace.canBuild)
     {
         return;
     }
     if (!BuildManager.instace.EnoughMoney)
     {
         rend.material.color = ErrorColor;
         return;
     }
     rend.material.color = hoverColor;
 }

 void OnMouseExit ()
 {
     rend.material.color = originalColor;
 }

}

Comment
Add comment · Show 2
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 Pinkuboxu · Sep 03, 2018 at 03:33 AM 0
Share

Are the objects being instantiated with code or are they setup manually in the editor? If you are setting them by hand be sure they are all from the same prefab. Also you may find that your draw calls are growing fast as I'm pretty sure you make a new instance material for each object when you call rend.material.color the first time you call it. I don't think that would contribute to your problem, but it might be better to create a material for each color ins$$anonymous$$d and swap them when you need to change the look. The only other thing I can say and I really don't know because I cannot see the setup you have for the level, is if the camera frustum and the objects bounds are messing up their rendering some how.

avatar image tormentoarmagedoom · Sep 03, 2018 at 08:54 AM 0
Share

The object have colliders?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DawdleDev · Sep 03, 2018 at 08:27 PM

If you're going to use OnMouseEnter and Exit, you're going to need something to call it. Either you can use a bunch of static colliders, or you can use an EventTrigger component, which may be more performant and doesn't have to use physics.

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

152 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make Rotation of HingeJoint2D constant via mouse button C# 1 Answer

Fast Clicking problem 0 Answers

Cooldown between MouseClick Detection 1 Answer

Show and hide more buttons after clicking different button 1 Answer

Text Mesh - Mesh Renderer is always on top, but Canvas Renderer - Image - Canvas World Space render is not 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