-
Notifications
You must be signed in to change notification settings - Fork 0
/
RayPosition.cs
32 lines (30 loc) · 1.07 KB
/
RayPosition.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayPosition : MonoBehaviour
{
private Camera mainCamera;
private Ray ray;
private RaycastHit hit;
private Vector3 mousePos, hitPosition;
public float radius = 11;
public float softness = 4;
public float moveSpeed = 15;
// Start is called before the first frame update
void Start()
{
mainCamera = this.GetComponent<Camera>();
}
// Update is called once per frame
void Update()
{
mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
ray = mainCamera.ScreenPointToRay(mousePos);
if (Physics.Raycast(ray, out hit)) {
hitPosition = Vector3.MoveTowards(hitPosition, hit.point, moveSpeed * Time.deltaTime);
Shader.SetGlobalVector("_Position", new Vector4(hitPosition.x, hitPosition.y, hitPosition.z, 1));
}
Shader.SetGlobalFloat("_Radius", this.radius);
Shader.SetGlobalFloat("_Softness", this.softness);
}
}