- Home /
Question by
TheFIshDivision · Mar 15, 2020 at 07:53 PM ·
c#error
not all lines of code running c#
So I made some code a while ago it all worked fine. then I decided to add something to it that didn't affect any of the other lines but, when I tested the code all the other lines other than the new ones just didn't run. There were no errors they just didn't run.`public class Inventory : MonoBehaviour { public Text[] inventoryText;
public Text selectionText;
public Image[] icons;
public GameObject woodsword;
int selectedTile;
int[] counts = new int[18];
string[] names = new string[] { "dirt", "grass", "stone", "coal", "iron", "gold", "diamond", "aquamarine", "Glass", "Sand", "Wooden Pickaxe", "Tree", "Wood", "Stone pickaxe", "Iron Pickaxe", "Wooden sword", "Wooden Wall", "Bat Meat" };
public GameObject[] tiles = new GameObject[18];
void Update()
{
if(selectedTile < 0)
{
selectedTile = counts.Length - 1;
}
if(selectedTile > counts.Length - 1)
{
selectedTile = 0;
}
if(Input.GetKeyDown(KeyCode.UpArrow))
{
selectedTile++;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
selectedTile--;
}
selectionText.text = "Selected Tile: " + names[selectedTile];
if (Input.GetMouseButtonDown(1))
{
if(counts[selectedTile] > 0)
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 placePos = new Vector3(Mathf.Round(mousePos.x), Mathf.Round(mousePos.y), 0f);
if (Physics2D.OverlapCircleAll(placePos, 0.25f).Length == 0)
{
GameObject newTile = Instantiate(tiles[selectedTile], placePos, Quaternion.identity) as GameObject;
counts[selectedTile]--;
}
}
}
if (selectedTile == 17)
{
if (Input.GetKeyDown(KeyCode.E))
{
if (counts[17] >= 1)
{
GameObject.Find("Character").GetComponent<playerhp>().HP += 3; ;
counts[17] -= 1;
}
}
}
if (selectedTile == 10)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (counts[12] >= 5)
{
counts[10]++;
counts[12] -= 5;
}
}
}
if (selectedTile == 13)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (counts[12] >= 2)
{
if (counts[2] >= 3)
{
counts[13]++;
counts[12] -= 2;
counts[2] -= 3;
}
}
}
}
if (selectedTile == 14)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (counts[12] >= 2)
{
if (counts[4] >= 3)
{
counts[14]++;
counts[12] -= 2;
counts[4] -= 3;
}
}
}
}
if (selectedTile == 8)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (counts[9] >= 2)
{
counts[8]++;
counts[9] -= 2;
}
}
}
if (selectedTile == 15)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (counts[12] >= 3)
{
counts[15]++;
counts[12] -= 3;
}
}
}
if (counts[2] == 1)
{
if (counts[10] == 0)
{
counts[2] -= 1;
}
}
if (counts[3] == 1)
{
if (counts[10] == 0)
{
counts[3] -= 1;
}
}
if (counts[4] == 1)
{
if (counts[13] == 0)
{
counts[4] -= 1;
}
}
if (counts[5] == 1)
{
if (counts[14] == 0)
{
counts[5] -= 1;
}
}
if (counts[6] == 1)
{
if (counts[14] == 0)
{
counts[6] -= 1;
}
}
if (counts[7] == 1)
{
if (counts[14] == 0)
{
counts[7] -= 1;
}
}
if (selectedTile == 16)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (counts[12] >= 1)
{
counts[16] += 4;
counts[12] -= 1;
}
}
}
if (selectedTile == 15)
{
if(counts[15] == 1)
{
woodsword.SetActive(true);
}
}
if (selectedTile != 15)
{
if (counts[15] == 1)
{
woodsword.SetActive(false);
}
}
//This is the only part that runs
inventoryload();
}
void inventoryload()
{
if (counts[0] >= 1)
{
inventoryText[0].text = "Dirt: " + counts[0];
}
if (counts[1] >= 1)
{
inventoryText[1].text = "Grass: " + counts[1];
}
if (counts[2] >= 1)
{
inventoryText[2].text = "Stone: " + counts[2];
}
if (counts[3] >= 1)
{
inventoryText[3].text = "Coal: " + counts[3];
}
if (counts[4] >= 1)
{
inventoryText[4].text = "Iron: " + counts[4];
}
if (counts[5] >= 1)
{
inventoryText[5].text = "Gold: " + counts[5];
}
if (counts[6] >= 1)
{
inventoryText[6].text = "Diamond: " + counts[6];
}
if (counts[7] >= 1)
{
inventoryText[7].text = "Marine: " + counts[7];
}
if (counts[8] >= 1)
{
inventoryText[8].text = "Glass: " + counts[8];
}
if (counts[9] >= 1)
{
inventoryText[9].text = "Sand: " + counts[9];
}
if (counts[10] >= 1)
{
inventoryText[10].text = "Wood pik: " + counts[10];
}
if (counts[11] >= 1)
{
inventoryText[11].text = "Tree: " + counts[11];
}
if (counts[12] >= 1)
{
inventoryText[12].text = "Wood: " + counts[12];
}
if (counts[13] >= 1)
{
inventoryText[13].text = "Stone pik: " + counts[13];
}
if (counts[14] >= 1)
{
inventoryText[14].text = "Iron pik: " + counts[14];
}
if (counts[15] >= 1)
{
inventoryText[15].text = "Sword: " + counts[15];
}
if (counts[16] >= 1)
{
inventoryText[16].text = "Woodwall: " + counts[16];
}
if (counts[17] >= 1)
{
inventoryText[17].text = "Batmeat: " + counts[17];
}
if (counts[0] == 0)
{
inventoryText[0].text = "";
}
if (counts[1] == 0)
{
inventoryText[1].text = "";
}
if (counts[2] == 0)
{
inventoryText[2].text = "";
}
if (counts[3] == 0)
{
inventoryText[3].text = "";
}
if (counts[4] == 0)
{
inventoryText[4].text = "";
}
if (counts[5] == 0)
{
inventoryText[5].text = "";
}
if (counts[6] == 0)
{
inventoryText[6].text = "";
}
if (counts[7] == 0)
{
inventoryText[7].text = "";
}
if (counts[8] == 0)
{
inventoryText[8].text = "";
}
if (counts[9] == 0)
{
inventoryText[9].text = "";
}
if (counts[10] == 0)
{
inventoryText[10].text = "";
}
if (counts[11] == 0)
{
inventoryText[11].text = "";
}
if (counts[12] == 0)
{
inventoryText[12].text = "";
}
if (counts[13] == 0)
{
inventoryText[13].text = "";
}
if (counts[14] == 0)
{
inventoryText[14].text = "";
}
if (counts[15] == 0)
{
inventoryText[15].text = "";
}
if (counts[16] == 0)
{
inventoryText[16].text = "";
}
if (counts[17] == 0)
{
inventoryText[17].text = "";
}
}
public void Add(int tileType, int count)
{
counts[tileType] += count;
}
} `
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Selecting Object From Top Causes NullReference 1 Answer
error on getint c# 0 Answers