Unity Mouse Personalization

Source: Internet
Author: User

The original version, the API can be directly set mouse display or not, the new version is changed, first up and down the old shop version;

1. Ideas:

    • In some games, the mouse is often hidden, or there are brilliant animations in place of the mouse display.
    • The principle is to hide the mouse (not display) up, set a sprite coordinates for the mouse coordinates. Of course the code should be put in the update.
    • Note: This script cannot be hung on the camera, otherwise there will be a mouse flicker situation.

Incidentally, attach a previous script:

  

Instance code:

 Public Dfguicamera Camera;  Public Dfslicedsprite Sprite;  Public float value = 0f; void Update () {// Hide Mouse false= Camera.camera.ScreenToWorldPoint (  New  Vector3 (INPUT.MOUSEPOSITION.X,INPUT.MOUSEPOSITION.Y,INPUT.MOUSEPOSITION.Z));}

2. First, to do the mouse personalized pictures, format if the cursor; see:

  

The second step: script mount, write the script, the default and click on the mouse image, drag and drop in it;

     Publictexture2d NorT;  Publictexture2d presst; PrivateVector2 hotspot; voidStart () {//screen.showcursor = false;//outofdate//cursor.setcursor (NorT, hotspot, Cursormode.auto);    }    Private voidUpdate () {if(Input.getmousebutton (0) {cursor.setcursor (presst, Vector2.zero, Cursormode.auto); //cursor.setcursor (Presst, Hospot, Cursormode.auto); //hotspot:the offset from the top left of the texture to use as the target point (must//Be within the bounds of the cursor). Default Selection Vector2.zero//the offset from the top of the texture as the target point (you must//In the range of the cursor)        }        Else{cursor.setcursor (NorT, Vector2.zero, Cursormode.auto); }    }  

Simply put, the above method to achieve the left mouse button click on the mouse will be set to the image of the corresponding picture.

In the code cursormode = Cursormode.forcesoftware; This mode means that when the mouse changes, the mouse moves outside the Unity window (for example, if you open a different software) the mouse in unity will still not disappear and is a set icon.

If Cursormode = Cursormode.auto This mode, there is only one mouse style, and when you move to the Unity window, there is no mouse in unity.

Unity Mouse Personalization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.