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 /
  • Help Room /
avatar image
0
Question by hkipping1 · Dec 14, 2019 at 02:16 PM · scripting problemscript.

Trying to add 10 cursors, after adding 3rd one getting Bool error,Trying to add in more cursors types (10 total)

Hey all, hopefully someone can lend a hand, trying to add 10 cursors so when the player hovers over an object it will display a new cursor depending on the object. Manged to add 2 (Door and pickup) they're working but struggling in adding more, any thoughts on best next steps to add the other 8 cursors? script is below, thanks:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Events;
 
 public class MouseManager : MonoBehaviour
 {
     //Know what objects are clickable
     public LayerMask clickableLayer;
 
     //Swap Cursors per object
     public Texture2D pointer; //Normal Pointer
     public Texture2D target; //Cursor for clickable objects like the world
     public Texture2D doorway; //Cursor for doorways
     public Texture2D open; //Same cursor as doorway but used for opening chests etc
     public Texture2D combat; //Cursor combat actions
     public Texture2D locked; //Cursor to display a locked Door, chest etc
     public Texture2D key; //Key icon to unlock a door, chest etc
     public Texture2D pickup; //Cursor to pickup floor item
     public Texture2D build; //Cursor to build objects
     public Texture2D destroy; //Cursor to destroy built objects
     public Texture2D health; //Cursor to increase player health
     public Texture2D talk; //Cursor to talk to NPCs
 
 
     public EventVector3 OnClickEnvironment;
 
 
     // Update is called once per frame
     void Update()
     {
         RaycastHit hit;
 
         if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 50, clickableLayer.value))
         {
             bool door = false; //Doorway
             bool pick = false; //Pickup
             bool enter = false; //Open
             bool fight = false; //Combat
             bool locking = false; //Locked
             bool keyhole = false; //Key
             bool add = false; //Build
             bool remove = false; //Destroy
             bool heal = false; //Health
             bool chat = false; //Talk
 
             if (hit.collider.gameObject.tag == "Doorway")
             {
                 Cursor.SetCursor(doorway, new Vector2(16, 16), CursorMode.Auto);
                 door = true;
             }
 
             else if (hit.collider.gameObject.tag == "Pickup")
             {
                 Cursor.SetCursor(pickup, new Vector2(16, 16), CursorMode.Auto);
                 pick = true;
             }
 
             else
             {
                 Cursor.SetCursor(target, new Vector2(16, 16), CursorMode.Auto);
             }
 
             if (Input.GetMouseButtonDown(0))
             {
                 if (door)
                 {
                     Transform doorway = hit.collider.gameObject.transform;
 
                     OnClickEnvironment.Invoke(doorway.position);
                     Debug.Log("Player has touched or opened a door");
                 }
 
                 else if (pick)
                 {
                     Transform itemPos = hit.collider.gameObject.transform;
 
                     OnClickEnvironment.Invoke(itemPos.position);
                     Debug.Log("Player has been picked up or interacted with something, check object log for more infomation on this item");
                 }
 
                 else
                 {
                     OnClickEnvironment.Invoke(hit.point);
                 }
             }
         }
 
         else
         {
             Cursor.SetCursor(pointer, Vector2.zero, CursorMode.Auto);
         }
     }
 }
 
 [System.Serializable]
 public class EventVector3 : UnityEvent { },Hey, hopefully someone can lend me a hand, trying to add in more than one player cursor (So when some hovers over a door it displays a door icon, hovers over a chest, chest icon etc) but running into issues adding in more please find the script below, any thoughts for best next steps on adding the rest of the 8 cursor types?:
 
 if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 50, clickableLayer.value))
         {
             bool door = false; //Doorway
             bool pick = false; //Pickup
             bool enter = false; //Open
             bool fight = false; //Combat
             bool locking = false; //Locked
             bool keyhole = false; //Key
             bool add = false; //Build
             bool remove = false; //Destroy
             bool heal = false; //Health
             bool chat = false; //Talk
 
             if (hit.collider.gameObject.tag == "Doorway")
             {
                 Cursor.SetCursor(doorway, new Vector2(16, 16), CursorMode.Auto);
                 door = true;
             }
 
             else if (hit.collider.gameObject.tag == "Pickup")
             {
                 Cursor.SetCursor(pickup, new Vector2(16, 16), CursorMode.Auto);
                 pick = true;
             }
 
             else
             {
                 Cursor.SetCursor(target, new Vector2(16, 16), CursorMode.Auto);
             }
 
             if (Input.GetMouseButtonDown(0))
             {
                 if (door)
                 {
                     Transform doorway = hit.collider.gameObject.transform;
 
                     OnClickEnvironment.Invoke(doorway.position);
                     Debug.Log("Player has touched or opened a door");
                 }
 
                 else if (pick)
                 {
                     Transform itemPos = hit.collider.gameObject.transform;
 
                     OnClickEnvironment.Invoke(itemPos.position);
                     Debug.Log("Player has been picked up or interacted with something, check object log for more infomation on this item");
                 }
 
                 else
                 {
                     OnClickEnvironment.Invoke(hit.point);
                 }
             }
         }
 
         else
         {
             Cursor.SetCursor(pointer, Vector2.zero, CursorMode.Auto);
         }
     }
 }
 
 [System.Serializable]
 public class EventVector3 : UnityEvent { }
 
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 Larry-Dietz · Dec 14, 2019 at 08:38 PM 0
Share

Which line is throwing an error? Looking at your script, it looks like it should work fine, and adding more would just be the same as they way you did pickup.

Go ahead and add a 3rd, and if you get the error again, show us the code again, with the 3rd cursor added, and let us know which line is throwing the error, and what exactly the error says.

0 Replies

· Add your reply
  • Sort: 

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

290 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image

Related Questions

How to create a script for a vehicle fuel? 0 Answers

ArgumentOutOfRangeException is occuring when it shouldn't 0 Answers

Manual GUI Refresh 0 Answers

Trying to impliment a 2D sidescroller enemeny follow player AI. Getting UnassignedReferenceException. Now idea how to fix, been lurking for days 2 Answers

Script error and no Variables showing 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