Надо создать объект и двигать его по X. Но выдаётся ошибка, установил всем объектам(префабам) галочку statyc но изменений никаких using System.Collections; using System.Collections.Generic; using UnityEngine;
public class spawn : MonoBehaviour { Transform parentTransform = transform; public float speed = 5f; public GameObject[] objs = new GameObject[3];
using System.Collections.Generic;
using UnityEngine;
public class spawn : MonoBehaviour
{
Transform parentTransform = transform;
public float speed = 5f;
public GameObject[] objs = new GameObject[3];
private void Start()
{
StartCoroutine(CreatEnemy());
}
private IEnumerator CreatEnemy()
{
while (true)
{
// Создаем клон с локальными координатами
Instantiate(objs[UnityEngine.Random.Range(0, objs.Length)], parentTransform.TransformPoint(new Vector3(UnityEngine.Random.Range(-47, -20), 2.10f, UnityEngine.Random.Range(-7, 10))), Quaternion.Euler(0, 0, 0), parentTransform);
yield return new WaitForSeconds(3f);
}
}
private void Update()
{
for (int i = 0; i < objs.Length; i++)
{
if (objs[i] == null)
continue;
objs[i].transform.Translate(new Vector3(1, 0, 0) * speed * Time.deltaTime);
}
}
}