Unity update

I have a script help me to set shiftspeed to zero when its game over,it keeps going because it is on update under shift

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Parallaxer : MonoBehaviour
{
class PoolObject

{
public Transform transform;
public bool inUse;
public PoolObject(Transform t) { transform = t; }
public void Use() { inUse = true; }
public void Dispose()
{
inUse = false;
}

}
public GameObject Prefab;
public int poolSize;
public float shiftSpeed;
public float spawnRate;

public YSpawnRange ySpawnRange;
public Vector3 defaultSpawnPos;
public bool spawnImmediate;
public float minus;
public Vector3 immediateSpawnPos;
public Vector2 targetAspectRatio;
float spawnTimer;
float targetAspect;
PoolObject[ ] poolObjects;
GameManager game;
[System.Serializable]
public struct YSpawnRange
{
public float min;
public float max;

}

void Awake()

{
Configure();

}
void Start()

{
game = GameManager.Instance;

}
void OnEnable()
{
GameManager.OnGameoverComfirmed += OnGameoverComfirmed;
}

void OnDisable()
{
GameManager.OnGameoverComfirmed -= OnGameoverComfirmed;

}

void Configure()
{
targetAspect = targetAspectRatio.y / targetAspectRatio.x;
poolObjects = new PoolObject[poolSize];
for (int i = 0; i < poolObjects.Length; i++)
{
GameObject go = Instantiate(Prefab) as GameObject;
Transform t = go.transform;
t.SetParent(transform);
t.position = Vector3.one * 1000;
poolObjects = new PoolObject(t);
}
if (spawnImmediate)
{
SpawnImmediate();
}
}
void OnGameoverComfirmed()
{
for (int i = 0; i < poolObjects.Length; i++)
{
poolObjects*.Dispose();*
poolObjects_.transform.position = Vector3.one * 1000;
}
}
void Spawn()
{
Transform t = GetPoolObject();
if (t == null) return;
Vector3 pos = Vector3.zero;
pos.y = (defaultSpawnPos.x * Camera.main.aspect) / targetAspect;
pos.x = Random.Range(ySpawnRange.min, ySpawnRange.max);
t.position = pos;
}
void SpawnImmediate()
{
Transform t = GetPoolObject();
if (t == null) return;
Vector3 pos = Vector3.zero;
pos.y = (immediateSpawnPos.y * Camera.main.aspect) / targetAspect;
pos.x = Random.Range(ySpawnRange.min, ySpawnRange.max);
t.position = pos;
Spawn();
}
void Shift()
{_

for (int i = 0; i < poolObjects.Length; i++)
{
shiftSpeed= 1 + 0.01f * Time.time;
poolObjects_.transform.localPosition -= -Vector3.down * shiftSpeed * Time.deltaTime;
CheckDisposeObject(poolObjects*);*
}
}
void CheckDisposeObject(PoolObject poolObject)
{
if (poolObject.transform.position.y < (-8 * Camera.main.aspect) / targetAspect)
{
poolObject.Dispose();
poolObject.transform.position = Vector3.one * 1000;
}
}
Transform GetPoolObject()
{
for (int i = 0; i < poolObjects.Length; i++)
{
if (!poolObjects*.inUse)*
{
poolObjects*.Use();*
return poolObjects*.transform;*
}
}
return null;
}
void Update()
{
minus -=.5f;
if (game.gameOver) return;
Shift();
//spawnRate = 5 / ;
//spawnRate= 5 - 0.01f;
spawnTimer += Time.deltaTime;
if (spawnTimer > spawnRate)
{
Spawn();
spawnTimer = 0;
}
}
}_

Please edit that mess and put it it in code tags, as well as explain a little more what the issue is, as frankly theres just a wall of code. “it keeps going” is vague

1 Like

Are you aware that you posted the code for an object pooler?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

You may wish to try this approach, one tiny step at a time.

Imphenzia: How Did I Learn To Make Games:

1 Like