Пытаясь увеличить скорость движения появляющихся объектов, я могу добиться увеличения скорости только самого первого объекта во время выполнения функции, а скорость всех остальных объектов остается прежней
это скрипт для создания объектов. Он устанавливается на отдельный игровой объект.
Я новичок в C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawnerScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
public float timer = 0;
public float hightOffset = 10;
public Birdscript Bird;
// Start is called before the first frame update
void Start()
{
spawnPipe();
Bird = GameObject.FindGameObjectWithTag("Bird").GetComponent();
}
// Update is called once per frame
void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
if (Bird.birdIsAlive)
{
spawnPipe();
timer = 0;
}
}
}
void spawnPipe()
{
float lowestPoint = transform.position.y - hightOffset;
float highestPoint = transform.position.y + hightOffset;
Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
}
}
Это сценарий самого объекта канала. Я пытаюсь изменить переменную
"скорость перемещения"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pipeMoveScript : MonoBehaviour
{
public float moveSpeed = 5;
public float deadZone = -40;
public Birdscript Bird;
public float speedtime = 10;
private float timer = 0;
// Start is called before the first frame update
void Start()
{
Bird = GameObject.FindGameObjectWithTag("Bird").GetComponent();
}
public void Speedup(int speedToadd)
{
moveSpeed += speedToadd;
}
// Update is called once per frame
void Update()
{
if (timer < speedtime)
{
timer += Time.deltaTime;
}
else
{
Speedup(5);
timer = 0;
}
if (Bird.birdIsAlive)
{
transform.position = transform.position + (Vector3.left * moveSpeed) * Time.deltaTime;
}
if (transform.position.x < deadZone)
{
Debug.Log("pipe Deleted");
Destroy(gameObject);
}
}
}
Чтобы увеличить скорость передвижения, я добавил следующее. а также функция "ускорение"
if (timer < speedtime)
{
timer += Time.deltaTime;
}
else
{
Speedup(5);
timer = 0;
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... th-c-sharp
Попытка увеличить скорость перемещения объектов в единстве с C# ⇐ C#
Место общения программистов C#
-
Anonymous
1719115555
Anonymous
Пытаясь увеличить скорость движения появляющихся объектов, я могу добиться увеличения скорости только самого первого объекта во время выполнения функции, а скорость всех остальных объектов остается прежней
это скрипт для создания объектов. Он устанавливается на отдельный игровой объект.
Я новичок в C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeSpawnerScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
public float timer = 0;
public float hightOffset = 10;
public Birdscript Bird;
// Start is called before the first frame update
void Start()
{
spawnPipe();
Bird = GameObject.FindGameObjectWithTag("Bird").GetComponent();
}
// Update is called once per frame
void Update()
{
if (timer < spawnRate)
{
timer = timer + Time.deltaTime;
}
else
{
if (Bird.birdIsAlive)
{
spawnPipe();
timer = 0;
}
}
}
void spawnPipe()
{
float lowestPoint = transform.position.y - hightOffset;
float highestPoint = transform.position.y + hightOffset;
Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
}
}
Это сценарий самого объекта канала. Я пытаюсь изменить переменную
"скорость перемещения"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pipeMoveScript : MonoBehaviour
{
public float moveSpeed = 5;
public float deadZone = -40;
public Birdscript Bird;
public float speedtime = 10;
private float timer = 0;
// Start is called before the first frame update
void Start()
{
Bird = GameObject.FindGameObjectWithTag("Bird").GetComponent();
}
public void Speedup(int speedToadd)
{
moveSpeed += speedToadd;
}
// Update is called once per frame
void Update()
{
if (timer < speedtime)
{
timer += Time.deltaTime;
}
else
{
Speedup(5);
timer = 0;
}
if (Bird.birdIsAlive)
{
transform.position = transform.position + (Vector3.left * moveSpeed) * Time.deltaTime;
}
if (transform.position.x < deadZone)
{
Debug.Log("pipe Deleted");
Destroy(gameObject);
}
}
}
Чтобы увеличить скорость передвижения, я добавил следующее. а также функция "ускорение"
if (timer < speedtime)
{
timer += Time.deltaTime;
}
else
{
Speedup(5);
timer = 0;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78656493/trying-to-increase-move-speed-of-objects-in-unity-with-c-sharp[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия