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 _Andros · Mar 26, 2013 at 01:20 AM · mouseclickselectiononmousedowninstantiationselecting objects

Why Is the game object not selected? I'd like to understand why.

 using UnityEngine;
 using System.Collections;
 
 public class Selectable : MonoBehaviour {
     
     bool Selected;
     // Use this for initialization
     void Start () {
     Selected  = false;
     }
     
     // Update is called once per frame
     void Update () {
     
         if (Selected) {
              
             if (Input.GetKeyDown(KeyCode.Escape)){Selected = false;}
             Transform selectionDisk;
             selectionDisk = Instantiate(selectionHalo, transform.position, transform.rotation) as Transform;
             
         }
     }
     
     void OnMouseDown(){
         Selected = true;
     }
 }
 

The Script gets attached to any game object that I want to be able to select. So far the screen just looks at a cube, but the cube doesn't do anything on click. And now the compiler says the prefab for selection halo doesnt exist. I added a render call to change the color instead, but still no work.

Comment
Add comment · Show 5
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 Benproductions1 · Mar 26, 2013 at 01:36 AM 2
Share

Does it have a collider attached? How is it set up? What is your scene setup like?

avatar image Auggie · Mar 26, 2013 at 04:04 AM 0
Share

i don't see any OnCollision or OnTrigger functions here...i'm not really an expert but how exactly does your selection work? if you can tell us that maybe we can understand the problem better...

avatar image liamcary · Mar 26, 2013 at 05:23 AM 0
Share

From what we can see, nothing calls On$$anonymous$$ouseDown.

avatar image flamy · Mar 26, 2013 at 05:54 AM 0
Share

On$$anonymous$$ouseDown is a monobehaviour function, it need not be called. what he is missing is a collider I guess.

Check if selectionHalo object has some kind of collider attached to it.

avatar image _Andros · Mar 28, 2013 at 03:38 PM 0
Share

Thanks for the responses, but both the cube this script attaches to and the selection halo I am instantiating both include colliders as part of the game objects.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MalachiteBR · Aug 26, 2015 at 12:59 AM

According to: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html

"This function is not called on objects that belong to Ignore Raycast layer.

OnMouseDown can be a co-routine.

This event is sent to all scripts attached to the Collider or GUIElement."

Just make sure you are not missing anything, often when these mysterious problems occurs we probably are missing something.

PS. And try to make all your methods/functions private or public, according to your needs.

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
avatar image
0

Answer by kylebarker82 · Aug 26, 2015 at 01:28 PM

Rigidbody or a Collider is attached I assume. If so you can try OnMouseEnter() to debug in the console and debug the OnMouseDown() with the bool value of Selected. Also double check you have an EventSystem gameobject in the scene. this usually helps the onmousedown issues for me. Double check that the colliders are set as 3D or 2D depending on your scene setup.

Comment
Add comment · Show 1 · 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 kylebarker82 · Aug 26, 2015 at 04:20 AM 0
Share

also it looks like you're casting the instatiate as a transform and not a gameobject, if you're moving a game object, then move the prefab of the gameobject , by it's transform in the form of a gameobject, not make a duplicate transform to move the duplicate transform wherever you want. did that make sense. Try casting it as a gameobject, not a transform.

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

15 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

Related Questions

How do I select a group full of sprites, between two points? 1 Answer

Particle System Appear Where Clicked 1 Answer

Object Selection with large number of objects 1 Answer

How do I select a sprite's pixel by mouse click? 1 Answer

Activating only when mouse is held down on a button for 0.5s. 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