Otro método Unidad Camera.main.ScreenPointToRay(Input.mousePosition)
ray punto de partida: Cámara Cámara;-ray final: posición del ratón.
Este método convierte los píxeles a las coordenadas de pantalla de mundo 3D, con entre formas mundo cámara 3D un rayo.
Este método de escritura utilizando un ejemplo, un clic del ratón en la pantalla en el objeto, el objeto se gira 45 grados
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using UnityEngine;
using Random = UnityEngine.Random;
public class RayCamera : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
private RaycastHit hit;
// Update is called once per frame
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButton(0))
{
if (Physics.Raycast(ray, out hit, 1000))
{
hit.transform.Rotate(Vector3.up,45);
}
}
Debug.DrawLine(transform.position,hit.point,Color.green);
}
}