So I want my player to collide with an object and after that I want my enemy to start attacking and chasing the player. I have 2 scripts on my Enemy and the object I want the player to collide with.
Enemy Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFollow : MonoBehaviour
{
public GameObject player;
public float speed;
private float distance;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
distance = Vector2.Distance(transform.position, player.transform.position);
Vector2 direction = player.transform.position - transform.position;
transform.position = Vector3.MoveTowards(this.transform.position, player.transform.position, speed * Time.deltaTime);
}
}
Collision Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Colliding : MonoBehaviour
{
public
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisonEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("Player"));
}
}