Quantcast
Channel: Questions in topic: "xcode"
Viewing all articles
Browse latest Browse all 1047

What am I doing wrong?

$
0
0
Hi All! I am just jumping into the Unity world and have been reading a few books and following some tutorials but this project not let me off easy! Everything to my untrained eyes looks good its a memory game so the user has to repeat the pattern of the buttons lighting up but at the minute it just seems to be skipping through the IF and logging "wrong" Thanks, Jordan! public SpriteRenderer[] colours; private int colourSelect; //Countdown / Light Up Timer public float stayLit; private float stayLitCounter; public float waitBetweenLights; private float waitBetweenCounter; //Sequance private bool shouldBeLit; private bool shouldBeDark; public List activeSequence; private int positionInSequence; private bool gameActive; private int inputInSequence; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(shouldBeLit) { stayLitCounter -= Time.deltaTime; if (stayLitCounter < 0) { //Changing color to full brightness when picked from the array colours[activeSequence[positionInSequence]].color = new Color (colours[activeSequence[positionInSequence]].color.r, colours[activeSequence[positionInSequence]].color.g, colours[activeSequence[positionInSequence]].color.b, 0.2f); shouldBeLit = false; shouldBeDark = true; waitBetweenCounter = waitBetweenLights; positionInSequence++; } } if (shouldBeDark) { waitBetweenCounter -= Time.deltaTime; if (positionInSequence >= activeSequence.Count) { shouldBeDark = false; gameActive = true; } else { if (waitBetweenCounter < 0) { //Changing color to full brightness when picked from the array colours [activeSequence[positionInSequence]].color = new Color (colours[activeSequence[positionInSequence]].color.r, colours[activeSequence[positionInSequence]].color.g, colours[activeSequence[positionInSequence]].color.b, 1f); stayLitCounter = stayLit; shouldBeLit = true; shouldBeDark = false; } } } } public void StartGame() { Debug.Log ("StartGAME"); activeSequence.Clear (); positionInSequence = 0; inputInSequence = 0; colourSelect = Random.Range (0, colours.Length); activeSequence.Add(colourSelect); colours[activeSequence[positionInSequence]].color = new Color (colours[activeSequence[positionInSequence]].color.r, colours[activeSequence[positionInSequence]].color.g, colours[activeSequence[positionInSequence]].color.b, 1f); stayLitCounter = stayLit; shouldBeLit = true; } public void ColourPressed(int whichButton) { if (gameActive) { if (activeSequence [inputInSequence] == whichButton) { Debug.Log ("Correct"); inputInSequence++; if (inputInSequence >= activeSequence.Count) { positionInSequence = 0; inputInSequence = 0; colourSelect = Random.Range (0, colours.Length); activeSequence.Add (colourSelect); colours [activeSequence [positionInSequence]].color = new Color (colours [activeSequence [positionInSequence]].color.r, colours [activeSequence [positionInSequence]].color.g, colours [activeSequence [positionInSequence]].color.b, 1f); stayLitCounter = stayLit; shouldBeLit = true; gameActive = false; } } else { Debug.Log ("WRONG"); gameActive = false; } } }}

Viewing all articles
Browse latest Browse all 1047

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>