Вот код:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour {
//дистанция от которой он начинает видеть игрока
public float seeDistance;
//дистанция до атаки
public float attackDistance;
//скорость енеми
public float speed = 6;
//игрок
private Transform target;
void Start()
{
target = GameObject.FindWithTag("Player").transform;
}
void Update()
{
if (Vector3.Distance (transform.position, target.transform.position) < seeDistance) {
if (Vector3.Distance (transform.position, target.transform.position) > attackDistance)
{
transform.right = target.transform.position - transform.position;
transform.Translate (new Vector3 (speed * Time.deltaTime, 0, 0));
}
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour {
//дистанция от которой он начинает видеть игрока
public float seeDistance;
//дистанция до атаки
public float attackDistance;
//скорость енеми
public float speed = 6;
//игрок
private Transform target;
void Start()
{
target = GameObject.FindWithTag("Player").transform;
}
void Update()
{
if (Vector3.Distance (transform.position, target.transform.position) < seeDistance) {
if (Vector3.Distance (transform.position, target.transform.position) > attackDistance)
{
transform.right = target.transform.position - transform.position;
transform.Translate (new Vector3 (speed * Time.deltaTime, 0, 0));
}
}
}
}