'Cursor not appearing in Unity with Screen.lockCursor = false;
Unity version: 2017.2.0b11
In my game when the Inventory Panel is visible on the screen, the cursor should appear so that i can click and interact. I always have to press esc key to make the cursor visible and even from that the cursor disappears after clicking.
Below is my javascript script
var OurInventory : GameObject;
var InvStatus : int;
function Update(){
if (Input.GetButtonDown("Inventory")){
if (InvStatus == 0){
Screen.lockCursor = false;
InvStatus = 1;
OurInventory.SetActive(true);
}
else {
Screen.lockCursor = true;
OurInventory.SetActive(false);
InvStatus = 0;
}
}
}
Below is my C# script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shop01Access : MonoBehaviour {
public GameObject ShopInventory;
public GameObject Item01Text;
public GameObject Item02Text;
public GameObject Item03Text;
public GameObject Item04Text;
public GameObject ItemCompletion;
public GameObject CompleteText;
void OnTriggerEnter(){
ShopInventory.SetActive(true);
Screen.lockCursor = false;
GlobalShop.ShopNumber = 1;
Item01Text.GetComponent<Text>().text = "" + GlobalShop.Item01;
Item02Text.GetComponent<Text>().text = "" + GlobalShop.Item02;
Item03Text.GetComponent<Text>().text = "" + GlobalShop.Item03;
Item04Text.GetComponent<Text>().text = "" + GlobalShop.Item04;
}
public void Item01() {
ItemCompletion.SetActive(true);
CompleteText.GetComponent<Text>().text = "Are you sure you want to buy " + GlobalShop.Item01 + "?";
}
public void Item02() {
ItemCompletion.SetActive(true);
CompleteText.GetComponent<Text>().text = "Are you sure you want to buy " + GlobalShop.Item02 + "?";
}
public void Item03() {
ItemCompletion.SetActive(true);
CompleteText.GetComponent<Text>().text = "Are you sure you want to buy " + GlobalShop.Item03 + "?";
}
public void Item04() {
ItemCompletion.SetActive(true);
CompleteText.GetComponent<Text>().text = "Are you sure you want to buy " + GlobalShop.Item04 + "?";
}
public void CancelTransaction(){
ItemCompletion.SetActive(false);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
