On the first iteration (of the second script), everything works fine. On the second drag, however, things go really, really wonky. I'm not sure if I'm still running the same first script (from the first character) or if I'm running the new script from the second character. I put in some debugging code into the script so I could try & see what's going on. Here's the code:
void OnMouseUp ()
int j = 0;
for (int i = 0; i < LandingSpot.Length; i++)
if (MyCollider.IsTouching(LandingSpot[i]) )
//LandingSpot[i].enabled = false;
transform.position = LandingSpot[i].transform.position;
transform.localScale = OriginalScale;
//Now that we've dragged it, which one did we drag?
ClickLoc = -1;
print("ClickLoc a: " + ClickLoc);
if (StartPos.x >= -2.05f && StartPos.x <= -1.95f) ClickLoc = 1;
if (StartPos.x >= -0.10f && StartPos.x <= 0.10f) ClickLoc = 2;
if (StartPos.x >= 1.76f && StartPos.x <= 1.96f) ClickLoc = 3;
print("ClickLoc b: " + ClickLoc);
j = 1;
print("ClickLoc: " + ClickLoc);
print("StartPos: " + StartPos.x);
print("Animal: " + an);
if (ClickLoc == 1)
The first time I release the mouse, I get the "mouseUp" message, the "ClickLoc a" and "ClickLoc b" messages, and the three lines with "ClickLoc", "StartPos" and "Animal" from the FillSeat function.
On the second release, however.... if I picked up the animal from the first position, I get only the StartPos and Animal lines from FillSeat. Other selections can be even stranger.
Part of the problem MAY come from FillSeat itself:
GameObject T1 = GameObject.FindGameObjectsWithTag("Animal");
Since every possible character exists on the screen at the beginning of the game, and since I'm Instantiating even more copies of these guys, the computer may be getting confused as to which object I'm talking about.
I can't make the characters prefabs, because they'd lose their code. I would prefer a better way of searching for the objects; I know EXACTLY the screen coordinates of the three characters, which are NEVER going to change....
and once they've been dropped, I want to ignore the actual gameobject, and just record WHAT was placed where...
I have no idea why the print statements aren't printing on the second drag; the program IS running the FillSeat function (otherwise you wouldn't see the StartPos line); but it looks as is the variables aren't getting set or something. Is there a way to ensure that once I'm done with the FillSeat function that the script exits? I am really, REALLY lost on why this is acting this way...