- Home /
Question by
strudi1986 · Oct 29, 2017 at 06:15 PM ·
uigameobjectraycasthit
[SOLVED] Open GUI with RaycastHit on Gameobject?
Hi, i want to do if i click on a Gameobject in the Game that a GUI Window open (such a portrait or so) but i dont know why i get an nullreferenceexception.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class SelectionManager : NetworkBehaviour {
public PlayerGuiManager playerGuiMananager;
void Start ()
{
}
// Update is called once per frame
void Update () {
RaycastHit raycastHit = new RaycastHit ();
if ( Input.GetMouseButtonDown (0) )
{
if ( Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out raycastHit) )
{
if(raycastHit.collider.tag == "NPC" )
{
playerGuiMananager.ShowHideCharacterInfoPanel ();
//Debug.Log ("We hit " + raycastHit.collider.gameObject.name);
}
else
Debug.Log ("Nothing was hit");
}
}
}
}
on the PlayerGuiManager is the GUI attached i want to open, but i get a nullreference error. anyone have a clue why? thank you!
UPDATE:
found the answer by myself :) i had to pass true or false to show hide the gui! Thank you anyway :)
RaycastHit raycastHit = new RaycastHit ();
if ( Input.GetMouseButtonDown (0) )
{
if ( Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out raycastHit) )
{
if(raycastHit.collider.tag == "NPC" )
{
playerGuiMananager.ShowHideCharacterInfoPanel (true);
//Debug.Log ("We hit " + raycastHit.collider.gameObject.name);
}
else
playerGuiMananager.ShowHideCharacterInfoPanel (false);
Debug.Log ("Nothing was hit");
}
Comment
Your answer
