So in working with my game, there aren't any syntax or compile errors, but there's this one bug that I've been working on to fix for a few days on and off and I can't seem to make heads or tails of the reason why it doesn't work, let me explain.
This is what the player sees when they start out, and their actions are to be able to click on two wires on the same side (right-right and left-left) and the should both switch positions.
In this image,the blue wire was the first one clicked, and the highlight/highlightDirection variables I have set are assigned to 'w2' (the blue wire) and the 'topLeft' direction for the purpose of changing the wire's sprite correctly when it changes positions.
And now I've clicked on the yellow wire, setting the changelight/changelightDirection to 'w3' (the yellow wire) and the 'middleLeft' direction for the purpose of changing the wire's sprite correctly when it changes positions, and after changelight/changelightDirection have been assigned, the wires shoudl both switch positions, but instead, this happens.
Only the yellow wire (The changelight/changeligthDirection wire) switched sprites, and this has been consistent throughout all of the combinations possible.
To try and fix this, I've gone over the script for the TopLeft and MiddleLeft scripts dozens of times, yet for some reason the same problem persists, and only the second clicked wire changes positions TopLeft.cs
void OnMouseDown () {
if (levelManager.highlight == "none") {
levelManager.highlight = levelManager.leftTopWire;
levelManager.highlightDirection="topLeft";
} else {
levelManager.changelight = levelManager.leftTopWire;
levelManager.changelightDirection = "topLeft";
if (levelManager.highlight == "w1" || levelManager.changelight=="w1") {
wireOne.SpriteChange ();
}
if (levelManager.highlight == "w2" || levelManager.changelight=="w2") {
wireTwo.SpriteChange ();
}
if (levelManager.highlight == "w3" || levelManager.changelight=="w3") {
wireThree.SpriteChange ();
}
}
}
MiddleLeft.cs
void OnMouseDown () {
if (levelManager.highlight == "none") {
levelManager.highlight = levelManager.leftMiddleWire;
levelManager.highlightDirection="middleLeft";
} else {
levelManager.changelight = levelManager.leftMiddleWire;
levelManager.changelightDirection = "middleLeft";
if (levelManager.highlight == "w1" || levelManager.changelight=="w1") {
wireOne.SpriteChange ();
}
if (levelManager.highlight == "w2" || levelManager.changelight=="w2") {
wireTwo.SpriteChange ();
}
if (levelManager.highlight == "w3" || levelManager.changelight=="w3") {
wireThree.SpriteChange ();
}
}
}
In the code for each scripts, no matter if the that wire is assigned to either changelight or highlight, then that wire's script will run it's SpriteChange function, unless I'm missing something that's how the code should work, and suggestions on how to fix this?
EDIT: Here's the code for the SpriteChange() functions for scripts WireOne.cs, WireTwo.cs, WireThree.cs
public void SpriteChange(){
if (levelManager.changelight == "w1") {
if (levelManager.highlightDirection == "middleLeft" || levelManager.highlightDirection == "bottomLeft" || levelManager.highlightDirection == "topLeft") {
if (levelManager.highlightDirection == "middleLeft" && rightPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTop;
}
if (levelManager.highlightDirection == "middleLeft" && rightPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightMiddle;
}
if (levelManager.highlightDirection == "middleLeft" && rightPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownBottom;
}
if (levelManager.highlightDirection == "topLeft" && rightPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightTop;
}
if (levelManager.highlightDirection == "topLeft" && rightPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTop;
}
if (levelManager.highlightDirection == "topLeft" && rightPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTall;
}
if (levelManager.highlightDirection == "bottomeLeft" && rightPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTall;
}
if (levelManager.highlightDirection == "bottomLeft" && rightPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpBottom;
}
if (levelManager.highlightDirection == "bottomLeft" && rightPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightBottom;
}
} else {//This is if the highlight direction is from the right
if (levelManager.highlightDirection == "middleRight" && leftPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTop;
}
if (levelManager.highlightDirection == "middleRight" && leftPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightMiddle;
}
if (levelManager.highlightDirection == "middleRight" && leftPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpBottom;
}
if (levelManager.highlightDirection == "topRight" && leftPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightTop;
}
if (levelManager.highlightDirection == "topRight" && leftPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTop;
}
if (levelManager.highlightDirection == "topRight" && leftPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTall;
}
if (levelManager.highlightDirection == "bottomeRight" && leftPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTall;
}
if (levelManager.highlightDirection == "bottomRight" && leftPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownBottom;
}
if (levelManager.highlightDirection == "bottomRight" && leftPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightBottom;
}
}
}
else{ //This is if the wire is in the highlight instead of the changelight
if (levelManager.changelightDirection == "middleLeft" || levelManager.changelightDirection == "bottomLeft" || levelManager.changelightDirection == "topLeft") {
if (levelManager.changelightDirection == "middleLeft" && rightPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTop;
}
if (levelManager.changelightDirection == "middleLeft" && rightPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightMiddle;
}
if (levelManager.changelightDirection == "middleLeft" && rightPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownBottom;
}
if (levelManager.changelightDirection == "topLeft" && rightPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightTop;
}
if (levelManager.changelightDirection == "topLeft" && rightPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTop;
}
if (levelManager.changelightDirection == "topLeft" && rightPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTall;
}
if (levelManager.changelightDirection == "bottomeLeft" && rightPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTall;
}
if (levelManager.changelightDirection == "bottomLeft" && rightPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpBottom;
}
if (levelManager.changelightDirection == "bottomLeft" && rightPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightBottom;
}
} else {//This is if the changelight direction is from the right
if (levelManager.changelightDirection == "middleRight" && leftPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTop;
}
if (levelManager.changelightDirection == "middleRight" && leftPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightMiddle;
}
if (levelManager.changelightDirection == "middleRight" && leftPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpBottom;
}
if (levelManager.changelightDirection == "topRight" && leftPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightTop;
}
if (levelManager.changelightDirection == "topRight" && leftPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTop;
}
if (levelManager.changelightDirection == "topRight" && leftPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = downUpTall;
}
if (levelManager.changelightDirection == "bottomeRight" && leftPos == "Top") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownTall;
}
if (levelManager.changelightDirection == "bottomRight" && leftPos == "Middle") {
gameObject.GetComponent<SpriteRenderer> ().sprite = upDownBottom;
}
if (levelManager.changelightDirection == "bottomRight" && leftPos == "Bottom") {
gameObject.GetComponent<SpriteRenderer> ().sprite = straightBottom;
}
}
}
levelManager.highlight = "none";
levelManager.highlightDirection = "none";
levelManager.changelight = "none";
levelManager.changelightDirection = "none";
}
SpriteChange()
method? Does it changelevelManager.highlight
orlevelManager.changelight
? \$\endgroup\$ – Vaillancourt♦ Jun 29 '15 at 23:43