UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionUnknown script error EmptyUnknown script error

more_horiz
Ok... I have a problem, and I'm very much hoping that someone can help me with it.  So, here's the deal:  My first script Instantiates three random characters onto the screen, in pre-defined, specified locations which I know.  The second script is attached to each character game object, and detects when the mouse is down, dragged, and up.

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:

Code:

   void OnMouseUp ()
      {
        int j = 0;
        print("mouseUp");
        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);
                FillSeat();
                j = 1;
              }
          }
...
    void FillSeat()
      {
        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:

Code:

           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...

descriptionUnknown script error EmptyRe: Unknown script error

more_horiz
Now, this is interesting... for those who MAY be following this, if you've got similar problems, check your console for warning messages. Apparently, variables which are "set but never used" or have their values as null can screw up other things. When I removed (or used) these variables, the entire piece of code began to work properly. Go figure. In VisualBasic, such variables would just have been ignored. Not so here!

descriptionUnknown script error EmptyWe can help

more_horiz
Hello

We see that you have some issues with your project/script, however we can help you for a price. If you would like us to work for you then please feel free to contact us at http://RenntekStudios.co.uk or on Skype at RenntekStudios thanks

Our prices are very cheap. Little errors we can fix for free, otherwise projects we can discuss prices. Hope you get in touch shortly thank you...

descriptionUnknown script error EmptyRe: Unknown script error

more_horiz
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply