首先必须在场景中添加人物角色,搭建好需要的场景。
一.鼠标点击移动
using UnityEngine;
using System.Collections;
public class PlayerDir : MonoBehaviour {
public GameObject 【effect_click_prefab】;//在括号中的为点击地面的预制体所存放建立的
public Vector3 targetPosition = Vector3.zero;//建立点击地面位置所显示的三维数值的区域
private bool isMoving = false;//表示鼠标是否按下
private PlayerMove playerMove;//玩家移动
private Vector3 targeMovePosition; //移动位置
void Start() {
targetPosition = transform.position;
playerMove = this.GetComponent<PlayerMove>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0) && UICamera.hoveredObject == null)// 输入,获取鼠标按钮按下且在UICamera下的在对象为空时
{
Ray ray =Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo