using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Hero : MonoBehaviour
{
public NavMeshAgent agent;
public Animator anim;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; //碰撞信息
if(Physics.Raycast(ray, out hit))
{
agent.SetDestination(hit.point);
}
}
anim.SetFloat("speed", agent.velocity.magnitude);
}
}
2.让摄像机跟随绑定人物移动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Follow : MonoBehaviour
{
publi