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

public class EnemyBounceTowardScript : MonoBehaviour {

    GameObject player;
    float lastjumptime;

    public int type;

	// Use this for initialization
	void Start () {
        player = GameObject.Find("player");
	}
	
	// Update is called once per frame
	void Update () {
        Vector3 offset;
        if (player != null && Vector3.Distance(transform.position, player.transform.position) < 40)
        {
            offset = player.transform.position - transform.position;
        } else
        {
            offset = Random.onUnitSphere;
        }
        if (Time.time - lastjumptime > 1f && Time.time - GetComponent<CollisionRememberer>().lastcollisiontime < 0.1f)
        {
                
            Vector3 dir = (offset.normalized + 2.5f * Physs.up).normalized;
            float mul = Random.Range(0.5f, 2);
            GetComponent<Rigidbody2D>().AddForce(dir * 300 * mul);
            //print("jump");
            lastjumptime = Time.time;
        }
	}
}
