I have used this piece of code to avoid a drag of an object over a specific line, now it does not work anymore and i do not understand what the problem is. The idea is that when “selected_GameObject” passes over “bluePlayerY” the position should reset to that very same position so the object never passes the line.
public void OneFingerDragProcess (Gesturegesture) { ...
...
} else if (whatPlayerIsActive == "RED") {
print ("E");
if (selected_GameObject.transform.position.y <= bluePlayerY) {
print ("F: " + selected_GameObject.name);
selected_GameObject.transform.position = new Vector3 (0f, 0f, 0f);
// selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, bluePlayerY, selected_GameObject.transform.position.z);
}
}
The output (print) i get indicate that i do grab the object but the position is never triggered:
E
F: Enemy-01
It used to work so i am very puzzled and would very much appreciate some help.
Strange, this is a bigger portion of the code, what is strange is that the ADJUST THE EDGE BASED ON TYPE OF GAME portion of the code, to avoid object to be dragged outside of the scene, is still working perfectly. When i change the position in that sector to position = 0, 0, 0 it also works as expected?
This means that a bit down the code the same type of code does not work even if it is the same type of statements?
// ADJUST THE EDGE BASED ON TYPE OF GAME
if (selected_GameObject.transform.position.x <= -finalWidth) {
selected_GameObject.transform.position = new Vector3 (-finalWidth, selected_GameObject.transform.position.y, selected_GameObject.transform.position.z);
} else if (selected_GameObject.transform.position.x >= finalWidth) {
selected_GameObject.transform.position = new Vector3 (finalWidth, selected_GameObject.transform.position.y, selected_GameObject.transform.position.z);
}
if (selected_GameObject.transform.position.y <= -finalHeight) {
selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, -finalHeight, selected_GameObject.transform.position.z);
} else if (selected_GameObject.transform.position.y >= finalHeight) {
selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, finalHeight, selected_GameObject.transform.position.z);
}
if (gameMode == "LOCAL MULTIPLAYER") {
if (useProtectionZoneAtMultiplayer) { // THIS IS TO DISABLE THE PROTECTED QUADRANTS IN MULTIPLAYER MODE
whatPlayerIsActive = PlayerPrefs.GetString ("ACTIVE PLAYER");
if (whatPlayerIsActive == "BLUE") {
if (selected_GameObject.transform.position.y >= redPlayerY) {
print ("RED: " + selected_GameObject.name);
selected_GameObject.transform.position = new Vector3 (0f, 0f, 0f);
}
} else if (whatPlayerIsActive == "RED") {
print ("selected_GameObject.transform.position.y: " + selected_GameObject.transform.position.y + " | bluePlayerY: " + bluePlayerY);
if (selected_GameObject.transform.position.y <= bluePlayerY) {
print ("BEFORE BLUE: " + selected_GameObject.transform.position);
selected_GameObject.transform.position = new Vector3 (0f, 0f, 0f);
print ("AFTER BLUE: " + selected_GameObject.transform.position);
}
}
}
}
I just moved the code below and put it before the ADJUST THE EDGE BASED ON TYPE OF GAME and it works as expected meaning that the object is moved to 1,1,0. Now i am really puzzled as the same line of codes works above the piece that does not work ??
if (selected_GameObject.transform.position.y >= redPlayerY) {
print ("XXXX: " + selected_GameObject.name);
selected_GameObject.transform.position = new Vector3 (1f, 1f, 0f);
}
// ADJUST THE EDGE BASED ON TYPE OF GAME
The output i get is: INIT useProtectionZoneAtMultiplayer: True
…and it prints it only once. Despite that the useProtectionZoneAtMultiplayer flips between true and false during the process? …really do not understand that.
I even renamed useProtectionZoneAtMultiplayer to be sure there is no impact from outside but with the same result. I have searched all my code but there is only one place were it is updated, above.