- Home /
Int Value Keeps Growing and Reseting it under Start Function Isn't working
Hey! So my code to make a trigger and platform continuously spawn in front of the player works the first time it runs, then for some reason keeps growing. For example, the "Z" value starts at 580 and adds 400 every time a new trigger is hit. However, when I stop and restart the game it uses the previously high value instead of resetting. So if I run the game till the value hits 980, then the next time I start it starts at 980 the 1380 and so on. I tried storing the same info in playerprefs instead and it doesn't work either. Any help would be much appreciated. Here's my code below
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager: MonoBehaviour {
public GameObject[] Levels;
public int zScenePos = 580;
public int triggerPos = 450;
public GameObject Trigger;
void Start()
{
Instantiate(Trigger, new Vector3(0, 0, 50), transform.rotation);
zScenePos = 580;
triggerPos = 450;
}
public void NextTrigger ()
{
Instantiate(Levels[UnityEngine.Random.Range(0, 6)], new Vector3(0,0,zScenePos),transform.rotation);
Instantiate(Trigger, new Vector3(0, 0, triggerPos), transform.rotation);
zScenePos += 400;
triggerPos += 400;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Big Numbers - How to convert (k, M, a ) 4 Answers
Making a bubble level (not a game but work tool) 1 Answer
How do I create a save scene feature though int value in c# 2 Answers