- Home /
Raw Image or Render Texture block MouseOver (New to unity)
(Btw Im new-ish to unity, only been using it for just over a month) So I have an issue with getting a door to open, and I can imagine this will cause problems with further functions of the game.
I have a code that works perfectly fine, the door opens when the render texture raw image is turned off and the target texture from the camera is removed. However when it is on the prompt to open the door does not appear and the door cannot be opened
Heres the code for the Raycast for the Player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerCasting : MonoBehaviour
{
public static float DistanceFromTarget;
public float ToTarget;
void Update()
{
RaycastHit Hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Hit)) ;
{
ToTarget = Hit.distance;
DistanceFromTarget = ToTarget;
}
}
}
Heres the code for door:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DoorOpen: MonoBehaviour
{
public float TheDistance;
public GameObject ActionDisplay;
public GameObject ActionText;
public GameObject TheDoor;
public AudioSource BathroomDoorSound;
void Update()
{
TheDistance = PlayerCasting.DistanceFromTarget;
}
void OnMouseOver ()
{
if (TheDistance <= 2)
{
ActionDisplay.SetActive (true);
ActionText.SetActive (true);
}
if (Input.GetButtonDown("Action"))
{
if (TheDistance <= 2)
{
this.GetComponent<BoxCollider>().enabled = false;
ActionDisplay.SetActive(false);
ActionText.SetActive(false);
TheDoor.GetComponent<Animation>().Play("FirstDoorOpen");
BathroomDoorSound.Play();
}
}
}
void OnMouseExit()
{
ActionDisplay.SetActive(false);
ActionText.SetActive(false);
}
}
Thanks for reading, it may be a really easy fix but im not sure and if you need anything else just ask.
Answer by systemicgames · Jan 13 at 08:22 AM
Possibly the Canvas group is blocking raycasts, if you add a Canvas Group to your image and disable Block Raycasts, that might fix it...
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/class-CanvasGroup.html
Thanks for the information but that doesnt seem to have helped, I already had the canvas group but didnt have the blocking raycast off. However the issue is still occurring.
Your answer
Follow this Question
Related Questions
RenderTexture does not render canvas image. 0 Answers
how to make shader dont blend color with camera background? 0 Answers
Render to RenderTexture and Screen both 1 Answer
Canvas interaction on render texture to message PhysicsRaycaster 1 Answer
Can't get video to play on Render Texture (no code used) 1 Answer