Для начала скачайте отсюда https://github.com/Unity-Technologies/NavMeshComponents расширенные компоненты для Nav Mesh
Модели девочки и зомби:
Не забудьте на девочку и на зомби добавить компонент NavMeshAgent
Скрипты для ИИ.
//ZombieController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class ZombieController : MonoBehaviour
{
private GameObject target;
private NavMeshAgent agent;
private CharacterController controller;
void Awake()
{
target = GameObject.Find("/Player");
agent = GetComponent<NavMeshAgent>();
StartCoroutine(AttackPlayer());
}
void Update()
{
}
IEnumerator AttackPlayer()
{
while (true)
{
agent.SetDestination(target.transform.position);
yield return new WaitForSeconds(0.5f);
}
}
}
//PlayerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class PlayerController : MonoBehaviour
{
private NavMeshAgent agent;
private CharacterController controller;
void Awake()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
{
agent.destination = hit.point;
}
}
}
}
//CameraFollower.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
private Transform player;
public Vector3 offset = new Vector3(0, 2, -10);
void Awake()
{
player = GameObject.Find("/Player").transform;
}
void Update()
{
}
private void LateUpdate()
{
transform.position = player.position + offset;
}
}
Все скрипты архивом.
В ИТОГЕ ДОЛЖНО У ВАС ВЫЙТИ
Добавить комментарий