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 ShaneTheVeryTall · Mar 15, 2012 at 10:49 PM · texturespritecursormovieswap

Swap Custom Cursor for Animated Movie Texture or Sprite Sheet?

I'm trying to make a cursor that is basically the same as the Kinect hand cursor... So when you hover over something, the circle animates around the hand and when it's complete, a function will be called.

I have a sprite sheet prepared, and also a movie texture, but haven't been able to get either to work. Maybe I'm using the wrong approach to begin with (Texture2D seems to cause problems in both cases).

Any clues for me? Here's the code I have that works (just swaps one Texture2D for another). How would I make it show the animated cursor on hover?

 var myCursor:Texture2D;
 var myCursorHover:Texture2D;
 var cursorSizeX: int = 64;  // set to width of your cursor texture
 var cursorSizeY: int = 64;  // set to height of your cursor texture
 private var cursor:Texture2D;
 
 function Start(){
 cursor = myCursor;
 Screen.showCursor = false;
 }
 
 
 function OnGUI(){
     GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY),cursor);
 }
 
 function cursorHover(){
     cursor = myCursorHover;
 }
 
 function cursorRestore(){
     cursor = myCursor;
 }
Comment
Add comment · Show 1
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 DaveA · Mar 15, 2012 at 11:34 PM 0
Share

Also not working: Droid 4

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ShaneTheVeryTall · Mar 19, 2012 at 08:37 PM

I figured it out. Here is the working code, though I'm sure someone could write a more elegant version. I use a sprite texture that is 55 columns, one row.

 var cursorOff:Texture2D;
 var cursorOn:Texture2D;
 var cursorSizeX: int = 64;  // set to width of your cursor texture
 var cursorSizeY: int = 64;  // set to height of your cursor texture
 
 private var hovering : boolean;
 private var index : float;
 private var v1 : float = 0.0;
 private var v2 : float = 0.0;
 private var v3 : float = 0.0181818; //width of each sprite by percent of total width
 private var v4 : float = 1.0; //height
 private var myRect : Rect;
 
 
 function Start(){
     index = 0;
     hovering = false;
     Screen.showCursor = false;
 
 }
 
 function OnGUI(){
 
     if(hovering) {
         if(index <= 53){
             updateRect();
             GUI.DrawTextureWithTexCoords(Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY), cursorOn, myRect);
         }else{
             GUI.DrawTextureWithTexCoords(Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY),cursorOn, myRect);
         }
     }else {
         GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY + cursorSizeY/2, cursorSizeX, cursorSizeY),cursorOff);
     }
 }
 
 function cursorHover(){
     hovering = true;
 }
 
 function cursorRestore(){
     index = 0;
     hovering = false;
 }
 
 function updateRect() {
     index += Time.deltaTime * 25;
     //print(index);
     v1 = (v3 * Mathf.Floor(index));
     myRect = Rect(v1,v2,v3,v4);
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Using Sprite for Custom mouse Cursor using SetCursor 2 Answers

Possible to change size of cursor with Cursor.SetCursor? 0 Answers

How do I get my character to look in the direction of the cursor? 1 Answer

GUI Texture on Button Swap 3 Answers

How do you crop a Texture2d 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