You are on page 1of 1

using System.

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

public class Inimigo : MonoBehaviour


{
public float velocidade;
public Vector3 movimento;
private Vector3 posInicial;
private Vector3 posInimigo;

// Start is called before the first frame update


void Start()
{
posInicial=transform.position;
posInimigo=posInicial;
}

// Update is called once per frame


void Update()
{

transform.position=Vector3.MoveTowards(transform.position,posInimigo,velocidade *
Time.deltaTime);
if(transform.position==posInimigo){
if(posInimigo==posInicial){
posInimigo=posInicial + movimento;
}else{
posInimigo=posInicial;
}
}
}
private void OnTriggerEnter2D(Collider2D colidir){
if(colidir.CompareTag("player")){
colidir.GetComponent<Playercontroller>().GameOver();
}
}
}

You might also like