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
1
Question by DubstepDragon · Aug 16, 2013 at 07:52 PM · texturegameimagecursorfollow

Texture following cursor...

A simple question, how can I, when a button is clicked, instantiate a texture with the cursor as the center point (empty GameObject to define center, maybe?) and make it follow the cursor? I thought of having an empty follow the cursor and add the texture as a child, but that will not be so organized, and therefore I ask of you any simpler means of executing what I desire.

Thanks in advance!

[Note, this is not a request for a script, that is what the forums are for. But I ask of you, please, if you post any code that helps me, keep it in C#, if you can, to make life easier for me. Thank you.]

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

Answer by clunk47 · Aug 16, 2013 at 08:23 PM

I may be wrong, but it seems like you're wanting to click a button with a certain texture, and set that as the cursor? Try this out. You will attach this to your main camera, or some empty game object. You will need to assign the three textures in the inspector. This will create 3 buttons on the left side of the screen. Each button will show a texture that you have assigned. When you click each button, the image from the gui content will appear beneath the cursor as if you're dragging it. Hope I addressed your question appropriately.

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour 
 {
     Texture currentCursor;
     public Texture sel1;
     public Texture sel2;
     public Texture sel3;
     int w = 64;
     int h = 64;
     
     void OnGUI()
     {
         if(GUI.Button(new Rect(0, 0, w, h), sel1))
         {
             currentCursor = sel1;
         }
         
         if(GUI.Button (new Rect(0, 66, w, h), sel2))
         {
             currentCursor = sel2;    
         }
         
         if(GUI.Button(new Rect(0, 132, w, h), sel3))
         {
             currentCursor = sel3;
         }
         
         if(currentCursor != null)
         {
             GUI.DrawTexture(new Rect(Input.mousePosition.x - (w / 2), Screen.height - Input.mousePosition.y  - (h / 2), w, h), currentCursor);    
         }
     }
 }
 
Comment
Add comment · Show 7 · 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 DubstepDragon · Aug 17, 2013 at 11:18 PM 0
Share

That is kind of what I intended in the first place, but what I need is something like a button with an icon, but when you click on that button, a texture is selected, that can be placed down where the mouse is clicked. So it is kind of like selecting the texture by pressing its button, then being able to place the texture down... Tell me if that makes sense, and I can rephrase if needed.

avatar image DubstepDragon · Aug 21, 2013 at 06:40 PM 0
Share

Guys! PING!!!!!

avatar image clunk47 · Aug 21, 2013 at 08:51 PM 1
Share

What? lol...

avatar image getyour411 · Aug 21, 2013 at 09:06 PM 0
Share

Take a look at WorldtoScreenPoint and its inverse, I think that's what you are after.

avatar image DubstepDragon · Aug 21, 2013 at 09:20 PM 0
Share

I don't understand.

Show more comments

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

17 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

Related Questions

Changing a GUI texture while hovering over an object? 2 Answers

my gun wont follow my mouse 0 Answers

How to stop gradient banding? 2 Answers

Assigning UV Map to model at runtime 0 Answers

Loading texture file from png/jpg file on disk 5 Answers


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