摄像机跟随
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class followTarget : MonoBehaviour
{
private Vector3 offset;
private Transform playertr;
// Start is called before the first frame update
void Start()
{
playertr = GameObject.FindGameObjectWithTag("Player").transform;
offset = transform.position - playertr.position;
}
// Update is called once per frame
void Update()
{
transform.position = playertr.position + offset;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class removeTarget : MonoBehaviour
{
private NavMeshAgent playerAgent;
// Start is called before the first frame update
void Start()
{
playerAgent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollide = Physics.Raycast(ray, out hit);
if(isCollide)
{
playerAgent.SetDestination(hit.point);
}
}
}
}