- Home /
Problem with GUI Buttons with WorldSpace Canvas
Hi there!I have a problem that the GUI Buttons dont work or react if i click on them. The Canvas is in World Space, because i want to drop the GUI on a keypad model. I have tried several things now, but the buttons dont react. i give you the screens of my settings and my testcode. any ideas? Thank you!
Maybe something is hiding the raycast?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityEngine.UI;
namespace FPSHorror
{
public class Keypad : MonoBehaviour
{
public string correctPassword;
private string passwordInput;
//Buttons and Numbers for Keypad
public Button ButtonOneUp;
public Button ButtonTwoUp;
public Button ButtonThreeUp;
public Button ButtonFourUp;
public Button ButtonOneDown;
public Button ButtonTwoDown;
public Button ButtonThreeDown;
public Button ButtonFourDown;
private int numberOne;
private int numberTwo;
private int numberThree;
private int numberFour;
public Text numberOneText;
private bool keypadActive = false;
public Camera mainCam;
public Camera keypadCam;
//Initalizing Variables
private FirstPersonController playerController;
private GameManager_ToggleCursor toggleCursor;
// Use this for initialization
void Start ()
{
SetInitialReferences ();
}
void SetInitialReferences ()
{
playerController = GameObject.FindObjectOfType<FirstPersonController> ();
toggleCursor = GameObject.FindObjectOfType<GameManager_ToggleCursor> ();
}
// Update is called once per frame
void Update ()
{
}
public void MoveCameraToKeypad()
{
mainCam.enabled = false;
playerController.enabled = false;
gameObject.layer = LayerMask.NameToLayer ("Default");
toggleCursor.isCursorlocked = false;
keypadActive = true;
keypadCam.enabled = true;
}
public void CountNumberOneUp ()
{
numberOneText.text = numberOne.ToString ();
numberOne = numberOne += 1;
Debug.Log (numberOne);
print ("Clicked");
}
}
}
the parent of the canvas has a mesh collider. $$anonymous$$aybe that's blocking all the input from the canvas.
Ive tried to disable the mesh collider after changing the camera but the problem still exists. the ui buttons dont react on any clicks. Thanks for the help anyway!
since you have the buttons, either EventSystem or graphicsraycaster are missing.
no EventSystem and graphicsraycaster are there. dont work :(
Answer by callen · Feb 08, 2018 at 07:46 PM
World space canvas needs to know what camera is sending it events, did you set the Canvas.worldCamera to your keypadCam?
hmm ...there is still the problem with the World Space UI on these objects. If i have more than one prefabs of this in the scene the event cameras (?) are overlapping each other and i cant click the buttons on the object anymore. and i dont know how to fix this. or if there is even a solution for this. with one prefab in the scene the world space UI works fine and i click all the GUI Elements on the object. but if i add another one the gui dont work anymore as intended or only some elements are clickable and some are not because they are overlapping for some reason.
Answer by strudi1986 · Feb 09, 2018 at 08:54 PM
tanks that helped! i also need to uncheck "Ignore Reserved Graphics" in the "Graphic Raycaster" Component on the Canvas! THX
Your answer
![](https://koobas.hobune.stream/wayback/20220612152222im_/https://answers.unity.com/themes/thub/images/avi.jpg)