using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class DronesManager : MonoBehaviour
{
private List drones = new List();
// Start is called before the first frame update
void Start()
{
drones = GameObject.FindGameObjectsWithTag("Drone").ToList();
StartCoroutine(MoveDrone());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator MoveDrone()
{
for (int i = 0; i < drones.Count; i++)
{
var drone = drones[Random.Range(0, drones.Count)];
if (drone.GetComponent().go == false)
{
drone.GetComponent().movingSpeed = 0.5f;
drone.GetComponent().go = true;
}
yield return new WaitForSeconds(0.3f);
}
}
}
< /code>
Я зацикливаю список беспилотников в коровах, но каждый раз, когда некоторые из беспилотников не остаются двигаться. Пока все беспилотники не будут двигаться.using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DroneControl : MonoBehaviour
{
public float movingSpeed;
public bool go = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(go)
{
transform.position -= transform.forward * movingSpeed * Time.deltaTime;
}
}
}
< /code>
Это то, что я попробовал: < /p>
Все еще некоторые беспилотники остаются и не движутся. < /p>
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class DronesManager : MonoBehaviour
{
private List drones = new List();
private static System.Random rnd = new System.Random();
// Start is called before the first frame update
void Start()
{
drones = GameObject.FindGameObjectsWithTag("Drone").ToList();
StartCoroutine(MoveDrone());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator MoveDrone()
{
for (int i = 0; i < drones.Count; i++)
{
var numbers = new List(Enumerable.Range(0, drones.Count));
var droneIndices = numbers.OrderBy(a => rnd.Next()).ToList();
var drone = drones[droneIndices];
if (drone.GetComponent().go == false)
{
drone.GetComponent().movingSpeed = 0.5f;
drone.GetComponent().go = true;
}
yield return new WaitForSeconds(0.3f);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/698 ... not-moving
Почему некоторые из беспилотников не движутся? ⇐ C#
Место общения программистов C#
-
Anonymous
1757671616
Anonymous
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class DronesManager : MonoBehaviour
{
private List drones = new List();
// Start is called before the first frame update
void Start()
{
drones = GameObject.FindGameObjectsWithTag("Drone").ToList();
StartCoroutine(MoveDrone());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator MoveDrone()
{
for (int i = 0; i < drones.Count; i++)
{
var drone = drones[Random.Range(0, drones.Count)];
if (drone.GetComponent().go == false)
{
drone.GetComponent().movingSpeed = 0.5f;
drone.GetComponent().go = true;
}
yield return new WaitForSeconds(0.3f);
}
}
}
< /code>
Я зацикливаю список беспилотников в коровах, но каждый раз, когда некоторые из беспилотников не остаются двигаться. Пока все беспилотники не будут двигаться.using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DroneControl : MonoBehaviour
{
public float movingSpeed;
public bool go = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(go)
{
transform.position -= transform.forward * movingSpeed * Time.deltaTime;
}
}
}
< /code>
Это то, что я попробовал: < /p>
Все еще некоторые беспилотники остаются и не движутся. < /p>
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class DronesManager : MonoBehaviour
{
private List drones = new List();
private static System.Random rnd = new System.Random();
// Start is called before the first frame update
void Start()
{
drones = GameObject.FindGameObjectsWithTag("Drone").ToList();
StartCoroutine(MoveDrone());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator MoveDrone()
{
for (int i = 0; i < drones.Count; i++)
{
var numbers = new List(Enumerable.Range(0, drones.Count));
var droneIndices = numbers.OrderBy(a => rnd.Next()).ToList();
var drone = drones[droneIndices[i]];
if (drone.GetComponent().go == false)
{
drone.GetComponent().movingSpeed = 0.5f;
drone.GetComponent().go = true;
}
yield return new WaitForSeconds(0.3f);
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/69866319/why-some-of-the-drones-are-not-moving[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия