Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Awesomealan1 · Nov 22, 2021 at 02:01 PM · cameraraycastcanvasbeginnerrendertexture

Help with Raycast on Render Texture

Hey all, I'm a bit new to coding but I have a very specific issue that I haven't seen too much documentation/explanation for. I'm a bit of a beginner, but I'm trying to learn so bear with me. I've managed to find and fix most other issues in my game through trial and error, but this one issue is a bit hard to deal with. I'll lay out all the factors at play:

I'm using two canvas', one for a Render Texture and the other for UI elements. I may only need one, but even putting all of it under one canvas doesn't seem to fix the issue, so I don't think the canvas' themselves are the issue, I think it's the Raycast and Render Texture not working together right.

The first Canvas: I'm using a Render Texture and attaching it to the main camera so that I can achieve a low-res aesthetic, and it's working wonderfully. It basically just takes the main camera, then scales the resolution down, reapplying it to the camera through a texture, becoming the only thing the player sees. I think this is the root of the issue.

The second Canvas: UI elements, like text and other things. I have text in this canvas that appears if certain Raycast requirements are met. Again, I don't think the two canvas' matter, but I'm putting them here for all the cards to be on the table.

The Raycast script is as follows:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 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;
         
         }
     }
 }

Right now, what I'm trying to accomplish is having the player be able to change scenes by walking up to a door, the Raycast detecting a door trigger, and then UI elements appearing due to that detection. The script below for the door works when I disable the Render Texture canvas, so I know it works fine, but that disables the low-res aesthetic that I'm hoping for. When I activate the Render Texture canvas, no UI elements appear anymore, and even if they didn't, I can also no longer interact with the door. The UI not appearing is one thing, but the entire script not recognizing my door trigger leads me to believe that the Raycast x Render Texture aren't blended together correctly.

The door script is as follows:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class CabinDoor : MonoBehaviour
 {
 
     public float TheDistance;
     public GameObject ActionKey;
     public GameObject ActionText;
     public AudioSource DoorSound;
 
     void Update()
     {
         TheDistance = PlayerCasting.DistanceFromTarget;
     }
     void OnMouseOver ()
     {
         if (TheDistance <= 1.5)
         {
             ActionKey.SetActive(true);
             ActionText.SetActive(true);
 
         }
         if (Input.GetButtonDown("Action"))
         {
             if (TheDistance <= 1.5)
             {
                 ActionKey.SetActive(false);
                 ActionText.SetActive(false);
                 DoorSound.Play();
                 SceneManager.LoadScene(1);
             }
         }
         if (TheDistance >= 1.5)
         {
             ActionKey.SetActive(false);
             ActionText.SetActive(false);
 
         }
     }
 
     void OnMouseExit()
     {
         ActionKey.SetActive(false);
         ActionText.SetActive(false);
     }
 
 }


From what I've gathered from my day or two of researching this issue, the problem may be that the Raycast is not aligning with the Render Texture, or that I am in need of a second Raycast to reapply the coordinates of the Raycast onto the texture, or vice versa, I'm not exactly sure. I've seen some documentation for something like this, but am completely lost as to how I would apply that to this script.

Anyone have an idea of what code and where I could add it to make these two systems blend together properly? Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

250 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rendertexture raycast 0 Answers

How convert the coorardinates of the mouse from one camera to another? 2 Answers

Raycasting and Render Texture 3 Answers

Mouseclick GameObject through the view of a RenderTexture 0 Answers

Raycasting on render texture, minimap 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges