角色跟随鼠标位置旋转

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControler : MonoBehaviour
{
    void Start()
    {
    }
    void Update()
    {
        Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;
        if (Physics.Raycast(camRay, out hitInfo))
        {
            Vector3 target = hitInfo.point;
            //下面这句确保了鼠标指到角色身上不乱跳
            target.y = transform.position.y;
            transform.LookAt(target);
        }
    }
}

你可能感兴趣的:(学习笔记)