Прикреплю скрипт врага
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
GameObject player;
public Animator anima;
const float speedMove = 1.0f;
void Start()
{
player = GameObject.FindWithTag("Player");
anima = GetComponent<Animator>();
}
void Update()
{
float directionX = player.transform.position.x - transform.position.x;
float directionY = player.transform.position.y - transform.position.y;
if (Mathf.Abs(directionX) < 20 && Mathf.Abs(directionY)<20)
{
Vector3 pos = transform.position;
pos.x += Mathf.Sign(directionX) * speedMove * Time.deltaTime;
pos.y += Mathf.Sign(directionY) * speedMove * Time.deltaTime;
transform.position = pos;
}
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
GameObject player;
public Animator anima;
const float speedMove = 1.0f;
void Start()
{
player = GameObject.FindWithTag("Player");
anima = GetComponent<Animator>();
}
void Update()
{
float directionX = player.transform.position.x - transform.position.x;
float directionY = player.transform.position.y - transform.position.y;
if (Mathf.Abs(directionX) < 20 && Mathf.Abs(directionY)<20)
{
Vector3 pos = transform.position;
pos.x += Mathf.Sign(directionX) * speedMove * Time.deltaTime;
pos.y += Mathf.Sign(directionY) * speedMove * Time.deltaTime;
transform.position = pos;
}
}
}