Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.67 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class Paintpatch : MonoBehaviour
  7. {
  8.     public Transform TargetPaint;
  9.     public NavMeshAgent nav_agent;
  10.     private Vector3[] ver;
  11.    private bool switchersfunc;
  12.    public LineRenderer lr ;
  13.  
  14.   public  int sitchint = 0;
  15.     void Start()
  16.     {
  17.         lr = GetComponent<LineRenderer>();      
  18.         ver = new Vector3[20];    
  19.         lr.enabled = false;
  20.         nav_agent = GetComponent<NavMeshAgent>();
  21.     }
  22.  
  23.     void Update()
  24.     {  
  25.         if (TargetPaint != null)
  26.         {        
  27.             nav_agent.SetDestination(TargetPaint.position);
  28.              if(nav_agent.path.corners.Length == nav_agent.path.corners.Length)
  29.             {
  30.                 if (nav_agent.path.corners.Length > 1)
  31.                 {
  32.                     sitchint = nav_agent.path.corners.Length - 1;
  33.                
  34.                 }
  35.                 if (nav_agent.path.corners.Length < 1)
  36.                 {
  37.                     sitchint = 0;
  38.                     lr.enabled = false;
  39.                 }
  40.             }
  41.            if(sitchint!=3 && sitchint != 2 && sitchint != 1)
  42.             {
  43.                 lr.enabled = false;
  44.             }
  45.                 if (sitchint == 1)
  46.                 {
  47.                 Debug.Log(sitchint);
  48.  
  49.                     lr.enabled = true;
  50.                     lr.positionCount = 2;
  51.                     lr.SetPosition(0, nav_agent.path.corners[0]);
  52.                     lr.SetPosition(1, nav_agent.path.corners[nav_agent.path.corners.Length - 1]);
  53.                 }
  54.                 if (sitchint == 2)
  55.             {
  56.                 lr.enabled = true;
  57.                 lr.positionCount = 7;
  58.                     ver[0] = Vector3.Lerp(nav_agent.path.corners[0], nav_agent.path.corners[1], 0.67f);
  59.                     ver[1] = Vector3.Lerp(nav_agent.path.corners[1], nav_agent.path.corners[2], 0.33f);
  60.                     ver[2] = Vector3.Lerp(ver[0], ver[1], 0.5f);
  61.                     ver[3] = Vector3.Lerp(ver[2], nav_agent.path.corners[1], 0.88f);//-точка
  62.                     ver[4] = Vector3.Lerp(ver[3], ver[0], 0.5f);//-точка
  63.                     ver[5] = Vector3.Lerp(ver[3], ver[1], 0.5f);// - точка        
  64.                     lr.SetPosition(0, nav_agent.path.corners[0]);
  65.                     lr.SetPosition(1, ver[0]);
  66.                     lr.SetPosition(2, ver[4]);
  67.                     lr.SetPosition(3, ver[3]);
  68.                     lr.SetPosition(4, ver[5]);
  69.                     lr.SetPosition(5, ver[1]);
  70.                     lr.SetPosition(6, nav_agent.path.corners[nav_agent.path.corners.Length - 1]);
  71.                    
  72.                 }
  73.  
  74.  
  75.  
  76.  
  77.             if (sitchint == 3)
  78.             {
  79.                 lr.enabled = true;
  80.                 lr.positionCount = 12;
  81.                 ver[0] = Vector3.Lerp(nav_agent.path.corners[0], nav_agent.path.corners[1], 0.67f);
  82.                 ver[1] = Vector3.Lerp(nav_agent.path.corners[1], nav_agent.path.corners[2], 0.33f);
  83.  
  84.                                
  85.  
  86.                 ver[2] = Vector3.Lerp(ver[0], ver[1], 0.5f);
  87.                 ver[3] = Vector3.Lerp(ver[2], nav_agent.path.corners[1], 0.88f);//-точка
  88.  
  89.                                
  90.  
  91.                 ver[4] = Vector3.Lerp(ver[3], ver[0], 0.5f);//-точка
  92.                 ver[5] = Vector3.Lerp(ver[3], ver[1], 0.5f);// - точка      
  93.  
  94.  
  95.                         ver[6] = Vector3.Lerp(nav_agent.path.corners[1], nav_agent.path.corners[2], 0.67f);
  96.                        ver[7] = Vector3.Lerp(nav_agent.path.corners[2], nav_agent.path.corners[3], 0.33f);
  97.  
  98.                      ver[8] = Vector3.Lerp(ver[6], ver[7], 0.5f);
  99.  
  100.                         ver[9] = Vector3.Lerp(ver[8], nav_agent.path.corners[2], 0.88f);//-точка
  101.                         ver[10] = Vector3.Lerp(ver[9], ver[6], 0.5f);//-точка
  102.                       ver[11] = Vector3.Lerp(ver[9], ver[7], 0.5f);// - точка    
  103.                        
  104.  
  105.                 lr.SetPosition(0, nav_agent.path.corners[0]);
  106.                 lr.SetPosition(1, ver[0]);
  107.                 lr.SetPosition(2, ver[4]);
  108.                 lr.SetPosition(3, ver[3]);
  109.                 lr.SetPosition(4, ver[5]);
  110.                 lr.SetPosition(5, ver[1]);
  111.  
  112.                 lr.SetPosition(6, ver[6]);
  113.                 lr.SetPosition(7, ver[10]);
  114.                 lr.SetPosition(8, ver[9]);
  115.                 lr.SetPosition(9, ver[11]);
  116.                 lr.SetPosition(10, ver[7]);
  117.                 lr.SetPosition(11, nav_agent.path.corners[nav_agent.path.corners.Length - 1]);
  118.                
  119.             }
  120.  
  121.         }
  122.         else { lr.enabled = false; }
  123.        
  124.     }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement