Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- public Transform pointA = null, pointB = null;
- public float speed = 3.0f;
- bool _switch = false;
- public bool canPatrol = false;
- void Start()
- {
- }
- void Update()
- { if (canPatrol)
- {
- if (!_switch)
- {
- transform.position = Vector3.MoveTowards(transform.position, pointA.position, speed * Time.deltaTime);
- }
- if (_switch)
- {
- transform.position = Vector3.MoveTowards(transform.position, pointB.position, speed * Time.deltaTime);
- }
- if (transform.position == pointA.position)
- {
- _switch = true;
- }
- if (transform.position == pointB.position)
- {
- _switch = false;
- }
- }
- else
- {
- transform.Translate(transform.TransformDirection(transform.forward) * speed * Time.deltaTime);
- Destroy(gameObject, 5.0f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement