- Home /
Am I coding wrong for Unity C#?
Hello, I have been developing a software in unity with C# that predominantly is user interface based something equivocal to an RPG maker. I have ran into a problem where I am having to write well over 10 thousand lines of code to perform the simplest task.
For Example a player chooses an icon for a game object. That game object has 100 possible symbols it can be. I have an integer change from 0 to 1 because they picked the first option. I have to write an if() statement for every single possible value that int could be based on their selection from 0 to 100 to make matters worse there are hundreds of things the user can change, EACH with said 100 if statements.
Could it be my lack of knowledge and simpleton style of coding is why I have to spend so much time on a simple task?
Essentially I have my entire program built around voids that change hundreds of integers when a user interacts with the software and picks options, and millions of if statements for all the possible outcomes on each and every game object. I only code with integers, public voids, and if statements. Is there an easier way? A better way? I would greatly appreciate any advice or direction on how I could be coding in a way that better interacts with Unity.
Here is an example script called: Tracking System designed to tell me what users are selecting in scenes with 36 sprite options in 3 possible locations/GameObjects and 3 possible transitions (One of my smaller trackers honestly):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrackingSystem : MonoBehaviour
{
public int DialogueTracker = 0;
public int SpriteSelected = 0;
public int SecondarySelected = 0;
public int conclusion = 0;
// Start is called before the first frame update
void Start()
{
LoadTrackerInt();
}
// Update is called once per frame
void Update()
{
}
public void Secondary1()
{
SecondarySelected = 1;
}
public void Secondary2()
{
SecondarySelected = 2;
}
public void Secondary3()
{
SecondarySelected = 3;
}
public void Secondary4()
{
SecondarySelected = 4;
}
public void Secondary5()
{
SecondarySelected = 5;
}
public void Secondary6()
{
SecondarySelected = 6;
}
public void SelectedSpriteImage()
{
if(DialogueTracker == 2001)
{
if(SpriteSelected == 1)
{
//2001 means sentence 1 drop down was used to get to sprite selection page, 1 means they selected the first sprite on the list.
conclusion = 20011;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 2)
{
conclusion = 20012;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 3)
{
conclusion = 20013;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 4)
{
conclusion = 20014;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 5)
{
conclusion = 20015;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 6)
{
conclusion = 20016;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 7)
{
conclusion = 20017;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
if (SpriteSelected == 8)
{
conclusion = 20018;
PlayerPrefs.SetInt("SentenceOneConclusion", conclusion);
}
[...]
if (SpriteSelected == 20)
{
conclusion = 200220;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 21)
{
conclusion = 200221;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 22)
{
conclusion = 200222;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 23)
{
conclusion = 200223;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 24)
{
conclusion = 200224;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 25)
{
conclusion = 200225;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 26)
{
conclusion = 200226;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 27)
{
conclusion = 200227;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 28)
{
conclusion = 200228;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 29)
{
conclusion = 200229;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 30)
{
conclusion = 200230;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 31)
{
conclusion = 200231;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 32)
{
conclusion = 200232;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 33)
{
conclusion = 200233;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 34)
{
conclusion = 200234;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 35)
{
conclusion = 200235;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
if (SpriteSelected == 36)
{
conclusion = 200236;
PlayerPrefs.SetInt("SentenceTwoConclusion", conclusion);
}
}
[...]
if (SpriteSelected == 8)
{
conclusion = 38;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo2();
}
if (SpriteSelected == 9)
{
conclusion = 39;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo3();
}
if (SpriteSelected == 10)
{
conclusion = 310;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo4();
}
if (SpriteSelected == 11)
{
conclusion = 311;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo5();
}
if (SpriteSelected == 12)
{
conclusion = 312;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo6();
}
if (SpriteSelected == 13)
{
conclusion = 313;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree1();
}
if (SpriteSelected == 14)
{
conclusion = 314;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree2();
}
if (SpriteSelected == 15)
{
conclusion = 315;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree3();
}
if (SpriteSelected == 16)
{
conclusion = 316;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree4();
}
if (SpriteSelected == 17)
{
conclusion = 317;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree5();
}
if (SpriteSelected == 18)
{
conclusion = 318;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree6();
}
if (SpriteSelected == 19)
{
conclusion = 319;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour1();
}
if (SpriteSelected == 20)
{
conclusion = 320;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour2();
}
if (SpriteSelected == 21)
{
conclusion = 321;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour3();
}
if (SpriteSelected == 22)
{
conclusion = 322;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour4();
}
if (SpriteSelected == 23)
{
conclusion = 323;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour5();
}
if (SpriteSelected == 24)
{
conclusion = 324;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour6();
}
if (SpriteSelected == 25)
{
conclusion = 325;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive1();
}
if (SpriteSelected == 26)
{
conclusion = 326;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive2();
}
if (SpriteSelected == 27)
{
conclusion = 327;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive3();
}
if (SpriteSelected == 28)
{
conclusion = 328;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive4();
}
if (SpriteSelected == 29)
{
conclusion = 329;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive5();
}
if (SpriteSelected == 30)
{
conclusion = 330;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive6();
}
if (SpriteSelected == 31)
{
conclusion = 331;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix1();
}
if (SpriteSelected == 32)
{
conclusion = 332;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix2();
}
if (SpriteSelected == 33)
{
conclusion = 333;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix3();
}
if (SpriteSelected == 34)
{
conclusion = 334;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix4();
}
if (SpriteSelected == 35)
{
conclusion = 335;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix5();
}
if (SpriteSelected == 36)
{
conclusion = 336;
PlayerPrefs.SetInt("SpriteThreeConclusion5", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix6();
}
}
if (SecondarySelected == 4)
{
if (SpriteSelected == 1)
{
//3 means Sprite 1 drop down was used to get to sprite selection page, 1 means they selected the first sprite on the list.
conclusion = 41;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharOne1();
}
if (SpriteSelected == 2)
{
conclusion = 42;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharOne2();
}
if (SpriteSelected == 3)
{
conclusion = 43;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharOne3();
}
if (SpriteSelected == 4)
{
conclusion = 44;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharOne4();
}
if (SpriteSelected == 5)
{
conclusion = 45;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharOne5();
}
if (SpriteSelected == 6)
{
conclusion = 46;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharOne6();
}
if (SpriteSelected == 7)
{
conclusion = 47;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharTwo1();
}
if (SpriteSelected == 8)
{
conclusion = 48;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharTwo2();
}
if (SpriteSelected == 9)
{
conclusion = 49;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharTwo3();
}
if (SpriteSelected == 10)
{
conclusion = 410;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharTwo4();
}
if (SpriteSelected == 11)
{
conclusion = 411;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharTwo5();
}
if (SpriteSelected == 12)
{
conclusion = 412;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharTwo6();
}
if (SpriteSelected == 13)
{
conclusion = 413;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharThree1();
}
if (SpriteSelected == 14)
{
conclusion = 414;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharThree2();
}
if (SpriteSelected == 15)
{
conclusion = 415;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharThree3();
}
if (SpriteSelected == 16)
{
conclusion = 416;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharThree4();
}
if (SpriteSelected == 17)
{
conclusion = 417;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharThree5();
}
if (SpriteSelected == 18)
{
conclusion = 418;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharThree6();
}
if (SpriteSelected == 19)
{
conclusion = 419;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFour1();
}
if (SpriteSelected == 20)
{
conclusion = 420;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFour2();
}
if (SpriteSelected == 21)
{
conclusion = 421;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFour3();
}
if (SpriteSelected == 22)
{
conclusion = 422;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFour4();
}
if (SpriteSelected == 23)
{
conclusion = 423;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFour5();
}
if (SpriteSelected == 24)
{
conclusion = 424;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFour6();
}
if (SpriteSelected == 25)
{
conclusion = 425;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFive1();
}
if (SpriteSelected == 26)
{
conclusion = 426;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFive2();
}
if (SpriteSelected == 27)
{
conclusion = 427;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFive3();
}
if (SpriteSelected == 28)
{
conclusion = 428;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFive4();
}
if (SpriteSelected == 29)
{
conclusion = 429;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFive5();
}
if (SpriteSelected == 30)
{
conclusion = 430;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharFive6();
}
if (SpriteSelected == 31)
{
conclusion = 431;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharSix1();
}
if (SpriteSelected == 32)
{
conclusion = 432;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharSix2();
}
if (SpriteSelected == 33)
{
conclusion = 433;
PlayerPrefs.SetInt("SpriteFourConclusion5", conclusion);
FindObjectOfType<MonokumaFile4>().SetCharSix3();
}
[...]
if (SpriteSelected == 34)
{
conclusion = 634;
PlayerPrefs.SetInt("SpriteSixConclusion5", conclusion);
FindObjectOfType<MonokumaFile6>().SetCharSix4();
}
if (SpriteSelected == 35)
{
conclusion = 635;
PlayerPrefs.SetInt("SpriteSixConclusion5", conclusion);
FindObjectOfType<MonokumaFile6>().SetCharSix5();
}
if (SpriteSelected == 36)
{
conclusion = 636;
PlayerPrefs.SetInt("SpriteSixConclusion5", conclusion);
FindObjectOfType<MonokumaFile6>().SetCharSix6();
}
}
}
//More to come oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
public void SecondaryImageSelector6()
{
if (SecondarySelected == 1)
{
if (SpriteSelected == 1)
{
//1 means Sprite 1 drop down was used to get to sprite selection page, 1 means they selected the first sprite on the list.
conclusion = 11;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharOne1();
}
if (SpriteSelected == 2)
{
conclusion = 12;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharOne2();
}
if (SpriteSelected == 3)
{
conclusion = 13;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharOne3();
}
if (SpriteSelected == 4)
{
conclusion = 14;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharOne4();
}
if (SpriteSelected == 5)
{
conclusion = 15;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharOne5();
}
if (SpriteSelected == 6)
{
conclusion = 16;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharOne6();
}
if (SpriteSelected == 7)
{
conclusion = 17;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharTwo1();
}
if (SpriteSelected == 8)
{
conclusion = 18;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharTwo2();
}
if (SpriteSelected == 9)
{
conclusion = 19;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharTwo3();
}
if (SpriteSelected == 10)
{
conclusion = 110;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharTwo4();
}
if (SpriteSelected == 11)
{
conclusion = 111;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharTwo5();
}
if (SpriteSelected == 12)
{
conclusion = 112;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharTwo6();
}
if (SpriteSelected == 13)
{
conclusion = 113;
PlayerPrefs.SetInt("SpriteOneConclusion6", conclusion);
FindObjectOfType<MonokumaFile>().SetCharThree1();
}
if (SpriteSelected == 14)
[....]
if (SpriteSelected == 34)
{
conclusion = 234;
PlayerPrefs.SetInt("SpriteTwoConclusion6", conclusion);
FindObjectOfType<MonokumaFile2>().SetCharSix4();
}
if (SpriteSelected == 35)
{
conclusion = 235;
PlayerPrefs.SetInt("SpriteTwoConclusion6", conclusion);
FindObjectOfType<MonokumaFile2>().SetCharSix5();
}
if (SpriteSelected == 36)
{
conclusion = 236;
PlayerPrefs.SetInt("SpriteTwoConclusion6", conclusion);
FindObjectOfType<MonokumaFile2>().SetCharSix6();
}
}
if (SecondarySelected == 3)
{
if (SpriteSelected == 1)
{
//3 means Sprite 1 drop down was used to get to sprite selection page, 1 means they selected the first sprite on the list.
conclusion = 31;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharOne1();
}
if (SpriteSelected == 2)
{
conclusion = 32;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharOne2();
}
if (SpriteSelected == 3)
{
conclusion = 33;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharOne3();
}
if (SpriteSelected == 4)
{
conclusion = 34;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharOne4();
}
if (SpriteSelected == 5)
{
conclusion = 35;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharOne5();
}
if (SpriteSelected == 6)
{
conclusion = 36;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharOne6();
}
if (SpriteSelected == 7)
{
conclusion = 37;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo1();
}
if (SpriteSelected == 8)
{
conclusion = 38;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo2();
}
if (SpriteSelected == 9)
{
conclusion = 39;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo3();
}
if (SpriteSelected == 10)
{
conclusion = 310;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo4();
}
if (SpriteSelected == 11)
{
conclusion = 311;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo5();
}
if (SpriteSelected == 12)
{
conclusion = 312;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharTwo6();
}
if (SpriteSelected == 13)
{
conclusion = 313;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree1();
}
if (SpriteSelected == 14)
{
conclusion = 314;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree2();
}
if (SpriteSelected == 15)
{
conclusion = 315;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree3();
}
if (SpriteSelected == 16)
{
conclusion = 316;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree4();
}
if (SpriteSelected == 17)
{
conclusion = 317;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree5();
}
if (SpriteSelected == 18)
{
conclusion = 318;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharThree6();
}
if (SpriteSelected == 19)
{
conclusion = 319;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour1();
}
if (SpriteSelected == 20)
{
conclusion = 320;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour2();
}
if (SpriteSelected == 21)
{
conclusion = 321;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour3();
}
if (SpriteSelected == 22)
{
conclusion = 322;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour4();
}
if (SpriteSelected == 23)
{
conclusion = 323;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour5();
}
if (SpriteSelected == 24)
{
conclusion = 324;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFour6();
}
if (SpriteSelected == 25)
{
conclusion = 325;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive1();
}
if (SpriteSelected == 26)
{
conclusion = 326;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive2();
}
if (SpriteSelected == 27)
{
conclusion = 327;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive3();
}
if (SpriteSelected == 28)
{
conclusion = 328;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive4();
}
if (SpriteSelected == 29)
{
conclusion = 329;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive5();
}
if (SpriteSelected == 30)
{
conclusion = 330;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharFive6();
}
if (SpriteSelected == 31)
{
conclusion = 331;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix1();
}
if (SpriteSelected == 32)
{
conclusion = 332;
PlayerPrefs.SetInt("SpriteThreeConclusion6", conclusion);
FindObjectOfType<MonokumaFile3>().SetCharSix2();
}
Looks like you can simplify quite a bit of that, yeah. With a script nearly 10,000 lines long, this might be a troll but your last block can just be:
if (SecondarySelected == 6)
{
// Deter$$anonymous$$e whether to use 60, 600, maybe 6000 etc
var digits = (int)$$anonymous$$ath.Floor($$anonymous$$ath.Log10(SpriteSelected) + 1);
var conclusionBase = 6 * (int)$$anonymous$$ath.Pow(10, digits);
conclusion = SpriteSelected + conclusionBase;
PlayerPrefs.SetInt ("SpriteSixConclusion6", conclusion);
FindObjectOfType<$$anonymous$$onokumaFile6> ().SetCharOne1 ();
}
and similarly for your others.
The fact you bolded "I only code with integers, public voids, and if statements" really makes me suspect this is a troll. If this is real how have you been working like this? How did you get this far without stopping to think if there was an easier way?
Honestly this looks like the code I used to write when I was 13. It's possible they are young, inexperienced or simply a bit stubborn.
Anyway, this kind of speculation should be left to comments, not question answers.
Answer by tormentoarmagedoom · Oct 04, 2019 at 09:36 PM
OMG!
First, the answer to your question is YES, YOU ARE CODING WRONG!
You are crazy man!
Second, you should comence learing about using strings to fing a variable, or docompeose a string to get a value inside the srting and use it as a index of an array, instead of having multiple variables.
For example in this case :
public void Secondary1()
{
SecondarySelected = 1;
}
public void Secondary2()
{
SecondarySelected = 2;
}
[...]
You could just make a void function with a parameter:
public void Secondary(int Selection)
{
SecondarySelected = Selection;
}
Or then when you doing things like this:
if (SecondarySelected == 6)
{
[...]
if (SpriteSelected == 10)
{
conclusion = 610;
PlayerPrefs.SetInt("SpriteSixConclusion6", conclusion);
FindObjectOfType<MonokumaFile6>().SetCharTwo4();
}
if (SpriteSelected == 11)
{
conclusion = 611;
PlayerPrefs.SetInt("SpriteSixConclusion6", conclusion);
FindObjectOfType<MonokumaFile6>().SetCharTwo5();
}
[...]
}
Why are repeating this sentence every time?
PlayerPrefs.SetInt("SpriteSixConclusion6", conclusion);
Why not just do something like:
if (SecondarySelected == 6)
{
[...]
conclusion = 600+SpriteSelected; //So its 611 or 612 or whatever
PlayerPrefs.SetInt("SpriteSixConclusion6", conclusion);
// And find some smart way to find the method you need without need to write all **** options!
}
MAn, scripting is not about write a bible, is about stop and thing how is the best way to make the program to think each case without need to think you about it!.
PS: You saw i editoed your post to not be thaaat long.
Bye!
Answer by lgarczyn · Oct 04, 2019 at 10:51 PM
There are a few concepts that you need to learn to save yourself a lot of time. But yes, code repeated thousands of times per file is bad. A few examples of things you need to learn:
string concatenation (
"SpriteSixConclusion" + 6
will return"SpriteSixConclusion6"
)function arguments
function return values
loops
arrays
dictionaries
structs and classes
For example, you could have this
public void SetSpriteConclusion(string page, int sprite, int conclusion, Type monokuma, int charPage, int charSprite)
{
PlayerPrefs.SetInt("Sprite" + page + "Conclusion" + sprite, conclusion);
FindObjectOfType(monokuma).SetChar(charPage, charSprite);
}
which would be called like
SetSpriteConclusion("Six", 5, 636, typeof(MonokumaFile6), "Six", 6);
This would be the same as the last if statement in your file
Your answer
![](https://koobas.hobune.stream/wayback/20220612213005im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Rainbow Material Script Not properly running 1 Answer
Blocks falling in a column. 0 Answers
C# the position of the object 1 Answer