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
1
Question by AlanChatham · May 19, 2011 at 06:26 AM · waypointgizmo

Can you make a gizmo that changes behavior when clicked?

I'm making some waypoints with gizmos, and I'd like to make the simple gizmos that show the waypoints in the editor work in such a way that if you click on one, it changes from displaying a wire sphere to a wire cube, stays that way, and then if you click on it again, it will turn back to a sphere. So like a gizmo that toggles its shape each time you click on it (not to be confused with a gizmo that changes shape when selected; I know that can be done with OnDrawGizmosSelected).

Can this be done, or is there not enough input recognition in the editor to support such dynamic waypoints?

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

Answer by AlanChatham · May 24, 2011 at 06:14 AM

So, I figured out a kinda cludgey solution. It's not ideal (an ideal solution would have something where you could test for a mouse click, since now you have to select something else and then re-select the gizmo), but it works! In case someone else needs it, here's the code, with comments:

using UnityEngine; public class MovePoint : MonoBehaviour {

 public bool isStop = false;
 public int clickedCounter = 0;
 

private void OnDrawGizmos(){

     // Semi-transparent color
     Gizmos.color=new Color(1f,0,1f,.5f);
     if (isStop == true){
         Gizmos.DrawCube(transform.position, new Vector3(.5f,.5f,.5f));
     }
     else{
         Gizmos.DrawSphere(transform.position,.25f);
     }
     // If the clickedCounter is above 0, try to bring it down to zero
     // If it's currently selected, the OnDrawGizmosSelected function
             // will pull it back up
     if (clickedCounter > 0){
         clickedCounter--;
     }
 }
 
 void OnDrawGizmosSelected(){
     // If clickedCounter is zero,
             // it means we just clicked on it; otherwise this function
     // will have pulled the value up
     if (clickedCounter == 0)
         isStop = !isStop;
     // And set the counter to some value, so next cycle,
             // it won't be zero if it was selected last time
     clickedCounter = 5;
     // Finally, draw a bright box to highlight the selected gizmo
     Gizmos.color = Color.cyan;
     Gizmos.DrawWireCube(transform.position, new (.6f,.6f,.6f) );
 }
 

public

 bool GetIsStop(){
     return isStop;
 }
 
 void SetIsStop(bool x){
     isStop = x;
 }

}

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

1 Person is following this question.

avatar image

Related Questions

Manually Update/Redraw Scene View? 7 Answers

Gizmo Debug in Release Version 1 Answer

gizmo.drawline question : point a to b 2 Answers

How to Disable Transform Axis Gizmo Arrows 1 Answer

Transform tools appear far out from object and do not work. 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