lemansky

Untitled

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