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
0
Question by Kashaunzilla · Jun 15, 2011 at 12:56 AM · cursorcursor-customization

Changing Color of Curser

Ok in my fps game i want it so that way when my player curser goes over a enemy the curser will change to the color green. If it hovers over a enemy it will turn red letting your know to kill that player. And when your shooting and the bullet hits the target the curser will change from its orginal start to a X letting you know you are hitting the target!

Here is my idea for the script i would use for changing curser colors.

 private var N_curser = true;
 private var R_curser = false;
 private var G_cureser = false;
 
 function Awake ()
 {
     N_curser.enabled = true;
     R_curser.enabled = false;
     G_curser.enabled = false;
 
 }
 
 function OnMouseEnter ()
 {
     if ( gameObject.tag == "enemy" )
     {
          N_curser.enabled = false;
          R_curser.enabled = true;
          G_curser.enabled = false;
     }
 
     else if ( gameObject.tag == "friend" )
     {
          N_curser.enabled = false;
          R_curser.enabled = false;
          G_curser.enabled = true;
     }
 
 }
 
 function OnMouseExit ()
 {
     N_curser.enabled = true;
     R_curser.enabled = false;
     G_curser.enabled = false;
 
 }

I then got no clue on how to make the curser change its shape when you hit the target but i probably can do it if i wasnt hitting it though. Would the script above work?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dreamer · Jun 15, 2011 at 01:55 AM

The idea of using custom cursor is hide the cursor and render your own cursor texture and update the position to where your mouse is pointing each frame.

Hide your cursor by:

 Screen.showCursor = false;
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 Deeweext · May 29, 2013 at 01:31 PM

Example:

 var t_Ray_02 : Ray = Camera_Reference.v_MouseCamera.ScreenPointToRay(Input.mousePosition);
             var t_Hit_02 : RaycastHit;
             
             if(Physics.Raycast(t_Ray_02, t_Hit_02, 100.0))
             {
                 switch(t_Hit_02.collider.gameObject.name)
                 {
                     case "- Enemy" :
                     renderer.material.color = Color.red;
                     break;
                     
                     case "- Friend" :
                     renderer.material.color = Color.red;
                     break;
                     
                     default :
                     renderer.material.color = Color.white;
                     break;
                 }
             }


This is taken out of context, you have to change the camera refreence to main camera or whatever you use, this basicly just casts a ray from your view and checks against what it hits, then changes colour on a gameobject at the position of the cursor.

Furthermore, you can use camera render depth to get the mouse objects to appear ontop always.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Default Cursor hourglass during app load 2 Answers

How do I customize the image of the cursor? 4 Answers

Why does my cursor image have artifacts in WebGL? 2 Answers

Changed my cursor to something and cant change it to something else 1 Answer

How to get the current cursor texture? 0 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