- Home /
Question by
mzeman2203 · Apr 19, 2021 at 07:40 PM ·
c#unity 5cursor
Turning curser on and off
What I am trying to do is have different NPC menus, the game starts by turning off the curser. But when you click on the NPC it repeats so you can talk to the NPC.
using UnityEngine;
using System.Collections;
public class CursorScript : MonoBehaviour
{
public GameObject merchant;
public GameObject builder;
public bool canTurnMerchantOn;
public bool canTurnBuilderOn;
// Use this for initialization
void Start()
{
//Set Cursor to not be visible
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
if(builder.activeSelf == true && canTurnBuilderOn)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
canTurnMerchantOn = false;
}
if (builder.activeSelf == false)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
canTurnMerchantOn = true;
}
if (merchant.activeSelf == true && canTurnMerchantOn)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
canTurnBuilderOn = false;
}
if (merchant.activeSelf == false)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
canTurnBuilderOn = true;
}
}
}
The weird thing is the merchant npc works fine, then the builder npc the curser flickers and I cant click anything.
Comment