Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class AIController : MonoBehaviour
  6. {
  7.  
  8.     public Transform Player;
  9.     int MoveSpeed = 4;
  10.     int MaxDist = 7;
  11.     int MinDist = 3;
  12.     private Vector3 newPosition;
  13.     public Transform otherTransform;
  14.  
  15.     void Start()
  16.     {
  17.         var relativePoint = transform.InverseTransformPoint(otherTransform.position);
  18.  
  19.         if (relativePoint.x < 0.0)
  20.         {
  21.             print("Object is to the left");
  22.         }
  23.         else if (relativePoint.z > 0.0)
  24.         {
  25.             print("Object is to the right");
  26.         }
  27.         else
  28.         {
  29.             print("Object is directly ahead");
  30.         }
  31.     }
  32.  
  33.     void Update()
  34.     {
  35.         //transform.LookAt(Player);
  36.  
  37.         if (Vector3.Distance(transform.position, Player.position) >= MinDist)
  38.         {
  39.             newPosition = Player.position;
  40.             transform.position = Vector3.Lerp(transform.position, newPosition, Time.deltaTime * MoveSpeed);
  41.                        
  42.             if (Vector3.Distance(transform.position, Player.position) <= MaxDist)
  43.             {
  44.                 //Shoot();
  45.             }
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement