- Home /
Updating transform.position correctly to instantiated GameObjects
I am attempting to apply uniform updates to the position of instantiated objects incrementally after set durations of time (obstacles that are increasing in speed at the end of "rounds").
While the change is being applied, it is not being applied uniformly to all of the active gameObject instances according to my debug log. Some instances seem to be maintaining the initial speed and some seem to update.
I have a basic, barebones script attached to my instantiating GameObject.
public class ObjectMovement : MonoBehaviour
{
public float Speed;
void Update()
{
transform.position += Vector3.up * Speed * Time.deltaTime;
Debug.Log("Current Speed is " + Speed);
}
}
On a separate GameObject, I have a script for managing what "Round" the game is on where I would be applying changes to both the player object and the obstacle instantiations.
public class RoundControl : MonoBehaviour
{
private float TimeElapsed = 0;
private float EndRound = 10f;
public GameObject Obstacle;
private ObjectMovement FallingSpeed;
[HideInInspector] public float Round;
[HideInInspector] public bool RoundUp = false;
private void Start()
{
FallingSpeed = Obstacle.GetComponent<ObjectMovement>();
Round = 1;
}
void Update()
{
if (TimeElapsed <= EndRound)
{
TimeElapsed += Time.deltaTime;
}
if (TimeElapsed > EndRound)
{
NextRound();
TimeElapsed = 0;
RoundUp = false;
}
}
void NextRound()
{
Round = Round += 1;
FallingSpeed.Speed = FallingSpeed.Speed * 1.5f;
Debug.Log("Next Round! Round " + Round);
}
}
As is probably blatantly obvious I am at a pretty novice level with C#. I would be incredibly appreciative of any recommendations about how to go about fixing this problem.
Thanks so much!
Your answer
Follow this Question
Related Questions
How to carry over variable (transform.position) and use it as Vector3 for instanitating a prefab 2 Answers
Null Reference Exception transform position y 2 Answers
The instantiated prefab doesn't fire correctly from the player 2 Answers
Instantiate object in front of player? 2 Answers
transform.position on Instaniated object does not match inspector 0 Answers