Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class Paintpatch : MonoBehaviour
- {
- public Transform TargetPaint;
- public NavMeshAgent nav_agent;
- private Vector3[] ver;
- private bool switchersfunc;
- public LineRenderer lr ;
- public int sitchint = 0;
- void Start()
- {
- lr = GetComponent<LineRenderer>();
- ver = new Vector3[20];
- lr.enabled = false;
- nav_agent = GetComponent<NavMeshAgent>();
- }
- void Update()
- {
- if (TargetPaint != null)
- {
- nav_agent.SetDestination(TargetPaint.position);
- if(nav_agent.path.corners.Length == nav_agent.path.corners.Length)
- {
- if (nav_agent.path.corners.Length > 1)
- {
- sitchint = nav_agent.path.corners.Length - 1;
- }
- if (nav_agent.path.corners.Length < 1)
- {
- sitchint = 0;
- lr.enabled = false;
- }
- }
- if(sitchint!=3 && sitchint != 2 && sitchint != 1)
- {
- lr.enabled = false;
- }
- if (sitchint == 1)
- {
- Debug.Log(sitchint);
- lr.enabled = true;
- lr.positionCount = 2;
- lr.SetPosition(0, nav_agent.path.corners[0]);
- lr.SetPosition(1, nav_agent.path.corners[nav_agent.path.corners.Length - 1]);
- }
- if (sitchint == 2)
- {
- lr.enabled = true;
- lr.positionCount = 7;
- ver[0] = Vector3.Lerp(nav_agent.path.corners[0], nav_agent.path.corners[1], 0.67f);
- ver[1] = Vector3.Lerp(nav_agent.path.corners[1], nav_agent.path.corners[2], 0.33f);
- ver[2] = Vector3.Lerp(ver[0], ver[1], 0.5f);
- ver[3] = Vector3.Lerp(ver[2], nav_agent.path.corners[1], 0.88f);//-точка
- ver[4] = Vector3.Lerp(ver[3], ver[0], 0.5f);//-точка
- ver[5] = Vector3.Lerp(ver[3], ver[1], 0.5f);// - точка
- lr.SetPosition(0, nav_agent.path.corners[0]);
- lr.SetPosition(1, ver[0]);
- lr.SetPosition(2, ver[4]);
- lr.SetPosition(3, ver[3]);
- lr.SetPosition(4, ver[5]);
- lr.SetPosition(5, ver[1]);
- lr.SetPosition(6, nav_agent.path.corners[nav_agent.path.corners.Length - 1]);
- }
- if (sitchint == 3)
- {
- lr.enabled = true;
- lr.positionCount = 12;
- ver[0] = Vector3.Lerp(nav_agent.path.corners[0], nav_agent.path.corners[1], 0.67f);
- ver[1] = Vector3.Lerp(nav_agent.path.corners[1], nav_agent.path.corners[2], 0.33f);
- ver[2] = Vector3.Lerp(ver[0], ver[1], 0.5f);
- ver[3] = Vector3.Lerp(ver[2], nav_agent.path.corners[1], 0.88f);//-точка
- ver[4] = Vector3.Lerp(ver[3], ver[0], 0.5f);//-точка
- ver[5] = Vector3.Lerp(ver[3], ver[1], 0.5f);// - точка
- ver[6] = Vector3.Lerp(nav_agent.path.corners[1], nav_agent.path.corners[2], 0.67f);
- ver[7] = Vector3.Lerp(nav_agent.path.corners[2], nav_agent.path.corners[3], 0.33f);
- ver[8] = Vector3.Lerp(ver[6], ver[7], 0.5f);
- ver[9] = Vector3.Lerp(ver[8], nav_agent.path.corners[2], 0.88f);//-точка
- ver[10] = Vector3.Lerp(ver[9], ver[6], 0.5f);//-точка
- ver[11] = Vector3.Lerp(ver[9], ver[7], 0.5f);// - точка
- lr.SetPosition(0, nav_agent.path.corners[0]);
- lr.SetPosition(1, ver[0]);
- lr.SetPosition(2, ver[4]);
- lr.SetPosition(3, ver[3]);
- lr.SetPosition(4, ver[5]);
- lr.SetPosition(5, ver[1]);
- lr.SetPosition(6, ver[6]);
- lr.SetPosition(7, ver[10]);
- lr.SetPosition(8, ver[9]);
- lr.SetPosition(9, ver[11]);
- lr.SetPosition(10, ver[7]);
- lr.SetPosition(11, nav_agent.path.corners[nav_agent.path.corners.Length - 1]);
- }
- }
- else { lr.enabled = false; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement