Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RaycastWithRenderTexture : MonoBehaviour
{
[SerializeField] Transform cursor = null;
[SerializeField] Camera rtCamera = null;
RaycastHit hit;
[SerializeField] float offset = 0.3f;
void Update ()
{
var inputPos = Input.mousePosition;
var viewportPos = new Vector2(inputPos.x / Screen.width, inputPos.y / Screen.height);
var ray = rtCamera.ViewportPointToRay(viewportPos);
if( Physics.Raycast(ray, out hit)){
cursor.localPosition = hit.point + hit.normal * offset ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment