Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static GameObject way_point1;
- public static GameObject way_point2;
- void Start()
- {
- //это внутри GameObjectStartLevel
- prefab = Resources.Load("prefabs/way_point");
- way_point1 = Instantiate(prefab) as GameObject;
- //go_sp.AddComponent<Rigidbody>();
- x = 390;
- y = 10;
- z = 256;
- vector3 = new Vector3(x, y, z);
- way_point1.transform.position = vector3;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- namespace Assets.scripts.core.ai
- {
- public class PathAA : MonoBehaviour
- {
- NavMeshAgent agent;
- //CharMove charMove;
- //хранит папку точек
- //public GameObject waypointHolder;
- //занесение точек в лист
- public List<Transform> waypoints = new List<Transform>();
- //the next waypoint should have a longerdistance than the target tolerance
- float targetTolerance = 1;
- public int waypointIndex;
- Vector3 targetPos;
- Animator anim;
- public float waitingTime = 0;
- float patrolTimer;
- ////
- private void Start()
- {
- mob_action = "go_exit";
- ////
- //Setup the references
- agent = GetComponentInChildren<NavMeshAgent>();
- //charMove = GetComponent<CharMove>();
- //anim = GetComponent<Animator>();
- //Get all our waypoints
- //здесь GameObjectStartLevel
- waypoints.Add(GameObjectStartLevel.way_point1.transform);
- waypoints.Add(GameObjectStartLevel.way_point2.transform);
- void Update()
- {
- Patrolling();
- }
- /*The patrol function is simple
- we check if we reach one waypoint, we wait a bit, then go to the next one
- */
- void Patrolling() //cостояние патруль
- {
- agent.speed = 10;
- if (waypoints.Count > 0)
- {
- //заменить на коллайдер
- if (agent.remainingDistance < agent.stoppingDistance)
- {
- patrolTimer += Time.deltaTime;
- if (patrolTimer >= waitingTime)
- {
- if (waypointIndex == waypoints.Count - 1)
- {
- waypointIndex = 0;
- }
- else
- {
- waypointIndex++;
- }
- patrolTimer = 0;
- }
- }
- MoveTo(waypoints[waypointIndex].position, false, targetPos);
- }
- }
- //Because we are going to use following code a lot, we made it into a function to save time
- void MoveTo(Vector3 destination, bool aim, Vector3 lookPos)
- {
- agent.transform.position = transform.position;
- agent.destination = destination;
- Vector3 velocity = agent.desiredVelocity * 0.5f;
- //charMove.Move(velocity, aim, lookPos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement