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 Cedarrsgames · Aug 16, 2012 at 09:11 PM · errormousecursormouse cursor

Error with mouse cursor.

Hi, I am having some errors with my Mouse Center script. Can someone please help me?

Here are the 2 errors.

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) Mouse Cursor.Update () (at Assets/Horror Game Files/Scripts/Mouse Cursor.js:34)

and

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) Mouse Cursor.MoveMouse (Single mousePosX, Single mousePosY) (at Assets/Horror Game Files/Scripts/Mouse Cursor.js:45) Mouse Cursor.Update () (at Assets/Horror Game Files/Scripts/Mouse Cursor.js:30)

Here is the script. (Below)

var normalCursor : Texture2D; // The texture for when the cursor isn't near a screen edge var leftCursor : Texture2D; // The texture for the cursor when it's at the left edge var rightCursor : Texture2D; // Ditto, right edge var upCursor : Texture2D; // Top edge var downCursor : Texture2D; // ...And bottom edge var nativeRatio = 1.3333333333333; // Aspect ratio of the monitor used to set up GUI elements private var lastPosition : Vector3; // Where the mouse position was last var normalAlpha = .5; // Normal alpha value of the cursor ... .5 is full var fadeTo = .2; // The alpha value the cursor fades to if not moved var fadeRate = .22; // The rate at which the cursor fades private var cursorIsFading = true; // Whether we should fade the cursor private var fadeValue : float;

// Scale the cursor so it should look right in any aspect ratio, and turn off the OS mouse pointer function Start() { // Slightly weird but necessary way of forcing float evaluation var currentRatio : float = (0.0 + Screen.width) / Screen.height; transform.localScale.x *= nativeRatio / currentRatio; Screen.showCursor = false; fadeValue = normalAlpha; lastPosition = Input.mousePosition; }

function Update() { var mousePos = Input.mousePosition; // If the mouse has moved since the last update if (mousePos != lastPosition) { lastPosition = mousePos; // Get mouse X and Y position as a percentage of screen width and height MoveMouse(mousePos.x/Screen.width, mousePos.y/Screen.height); } // Fade the alpha of the cursor if (cursorIsFading) { guiElement.color.a = fadeValue; fadeValue -= fadeRate * Time.deltaTime; if (fadeValue < fadeTo) { fadeValue = fadeTo; cursorIsFading = false; } } }

function MoveMouse(mousePosX : float, mousePosY : float) { // Make the cursor solid, and set fading to start in case mouse movement stops guiElement.color.a = fadeValue = normalAlpha; guiElement.texture = normalCursor; cursorIsFading = true;

 // If the mouse is on a screen edge, first make sure the cursor doesn't go off the screen, then give it the appropriate cursor
 if (mousePosX < .005) {
     mousePosX = .005;
     guiElement.texture = leftCursor;
 }
 if (mousePosX > .995) {
     mousePosX = .995;
     guiElement.texture = rightCursor;
 }
 if (mousePosY < .005) {
     mousePosY = .005;
     guiElement.texture = downCursor;
 }
 if (mousePosY > .995) {
     mousePosY = .995;
     guiElement.texture = upCursor;
 }
 
 transform.position.x = mousePosX;
 transform.position.y = mousePosY;

}

Can someone please help me out with these errors? Thanks.

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
0

Answer by ScroodgeM · Aug 17, 2012 at 07:35 AM

guiElement in your script is null. what is this should be?

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cursor disappears in unity. 1 Answer

JavaScript: _player.cursor(280) 1 Answer

'Camera' does not contain a definition for 'ScreenPointToRay' 1 Answer

Can't See Mouse Cursor In Game. 1 Answer

Unity 3D Screen.lockCursor Problems 2 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