using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyContro : MonoBehaviour {
// Use this for initialization
public float speed = 1;
int moveDir = 1;
Animator myAnimator;
void Start () {
myAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
transform.Translate(Vector2.right * speed *moveDir* Time.deltaTime);
}
private void OnCollisionEnter2D(Collision2D collision)
{
Vector2 co_dir = collision.contacts[0].normal;
float angle_right = Vector2.Angle(Vector2.right, co_dir);
float angle_left = Vector2.Angle(Vector2.left, co_dir);
float angle_down = Vector2.Angle(Vector2.down, co_dir);
if(angle_right < 45)
{
moveDir = 1;
}
if (angle_left < 45)
{
moveDir = -1;
}
if (angle_down <45)
{
myAnimator.Play("enemy_die");
Destroy(gameObject, 0.1f);
}
}
}