лови брат
public class Bad_Boys_move : MonoBehaviour
{
public float speed;
public float agroDistance;
private Rigidbody2D physic;
private Transform player;
private int i = 10;
private void Start()
{
physic = GetComponent<Rigidbody2D>();
player = GameObject.FindWithTag("Player").transform;
}
private void Update()
{
float distToPlayer = Vector2.Distance(transform.position, player.position);
if (true)
{
while (i == 10)
{
transform.rotation = player.transform.rotation;
}
}
if (distToPlayer < agroDistance)
{
StartHunting();
}
else
{
StopHunting();
}
}
void StartHunting()
{
// Направление к игроку
Vector2 direction = (player.position - transform.position).normalized;
// Устанавливаем скорость в направлении игрока
physic.velocity = direction * speed;
}
void StopHunting()
{
physic.velocity =
Vector2.zero ;
}
}
using UnityEngine;
public class Bad_Boys_move : MonoBehaviour
{
public float speed;
public float agroDistance;
private Rigidbody2D physic;
private Transform player;
private void Start()
{
physic = GetComponent<Rigidbody2D>();
player = GameObject.FindWithTag("Player").transform;
}
private void Update()
{
float distToPlayer = Vector2.Distance(transform.position, player.position);
if (distToPlayer < agroDistance)
{
StartHunting();
}
else
{
StopHunting();
}
}
void StartHunting()
{
// Направление к игроку
Vector2 direction = (player.position - transform.position).normalized;
// Устанавливаем скорость в направлении игрока
physic.velocity = direction * speed;
}
void StopHunting()
{
physic.velocity = Vector2.zero ;
}
}