Advertisement
lemansky

Untitled

Apr 4th, 2021
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Enemy : MonoBehaviour
  6. {
  7.  
  8.    
  9.     public Transform pointA = null, pointB = null;
  10.     public float speed = 3.0f;
  11.     bool _switch = false;
  12.  
  13.     public bool canPatrol = false;
  14.  
  15.     void Start()
  16.     {
  17.        
  18.     }
  19.  
  20.     void Update()
  21.     {   if (canPatrol)
  22.         {
  23.             if (!_switch)
  24.             {
  25.                 transform.position = Vector3.MoveTowards(transform.position, pointA.position, speed * Time.deltaTime);
  26.             }
  27.  
  28.             if (_switch)
  29.             {
  30.                 transform.position = Vector3.MoveTowards(transform.position, pointB.position, speed * Time.deltaTime);
  31.             }
  32.  
  33.             if (transform.position == pointA.position)
  34.             {
  35.                 _switch = true;
  36.             }
  37.  
  38.             if (transform.position == pointB.position)
  39.             {
  40.                 _switch = false;
  41.             }
  42.         }
  43.         else
  44.         {
  45.             transform.Translate(transform.TransformDirection(transform.forward) * speed * Time.deltaTime);
  46.             Destroy(gameObject, 5.0f);
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement