Last active
July 18, 2017 14:08
-
-
Save tsubaki/98abbf54f92ae6df3a0f5f9cee96c2ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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