Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Enemy : MonoBehaviour
{
public float speed = 50f;
public Vector3[] positions;
private int indexPosition;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.x > GameObject.Find("Player").transform.position.x) {
GetComponent().flipX = true; }
else {
GetComponent().flipX = false; }
transform.position = Vector3.MoveTowards(transform.position, positions[indexPosition], speed/1000);
if (transform.position == positions[indexPosition]) {
if (indexPosition < positions.Length - 1) {
indexPosition++;
}
else {
indexPosition = 0;
}
}
}
private void OnCollisionEnter2D(Collision2D other) {
if (other.gameObject.CompareTag("Player")) {
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.CompareTag("Player")) {
Destroy(gameObject);
}
}
}
Я попробовал спросить у своего преподаватель Unity, но прошло 2 урока, а проблема осталась
Я ожидал, что ошибка переместится из одного места в другое
Подробнее здесь: https://stackoverflow.com/questions/791 ... ty-2d-game