Попытка увеличить скорость перемещения объектов в единстве с C#C#

Место общения программистов C#
Ответить
Anonymous
 Попытка увеличить скорость перемещения объектов в единстве с C#

Сообщение 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;
}


Подробнее здесь: https://stackoverflow.com/questions/786 ... th-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»