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 { }
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.
Your answer
Follow this Question
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
Script error and no Variables showing 0 Answers