Не могу правильно повернуть врага по отношению к игроку
Добавлено: 18 дек 2018, 17:35
Помогите не могу правильно повернуть спрайт. Вот что происходит:
Вот код:
Вот код:
Синтаксис:
Используется 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));
}
}
}
}