using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class npcMovement : MonoBehaviour {
    public int speed = 10;
    public Vector3 direction = new Vector3(0,0,0);
    // Use this for initialization
    void Start () {
        Invoke("ChangeDir", Random.Range(1.0f,5.0f));
        direction = new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), 0.0f);
    }
	
	// Update is called once per frame
	void Update () {
        transform.position += direction * Time.deltaTime * speed;
        if (direction.x > 0.1)
        {
            GetComponent<SpriteRenderer>().flipX = true;
        }
        else if (direction.x < -0.1)
        {
            GetComponent<SpriteRenderer>().flipX = false;
        }
        transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.y + 100);
    }

    void ChangeDir () {
        direction = new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), 0);
        Invoke("ChangeDir", Random.Range(1.0f, 5.0f));
    }
}
