My codes don't work !

Hi
Some of my codes don’t work . I copied those from another script . They work in first script but don’t work in new one ( only some of them ). I don’t know where problem is ? . For example in follow codes , codes ( Lines 37-45 ) don’t work . Pls help me .

void Update ()  {
     
        }

                if (Input.GetMouseButtonDown (0)) {
                    Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
                    Vector2 mousePos2D = new Vector2 (mousePos.x, mousePos.y);

                    RaycastHit2D hit = Physics2D.Raycast (mousePos2D, Vector2.zero);

                 
                    if (hit.collider.gameObject.name == "aaa") {

                    score02 += 1;
                    act002b ();
                   }
            if (hit.collider != null && hit.collider.gameObject.name == "fff") {
                score03 += 1;
                act004b ();
            }

            }

        if (Input.GetMouseButtonDown (0)) {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
            Vector2 mousePos2D = new Vector2 (mousePos.x, mousePos.y);

            RaycastHit2D hit = Physics2D.Raycast (mousePos2D, Vector2.zero);


            if (hit.collider.gameObject.name == "ddd") {

                score01 += 1;
                act001b ();
            }

         if (hit.collider.gameObject.name == "ggg") {
                score05 += 1;
                act005b ();
            }

            if (hit.collider.gameObject.name == "eee") {
                score05c += 1;
                act005c ();
            }
             
    }



        }

And codes ( Lines 11-18) don’t work

    void act001b () {

        if (score01 == 2) {

            hhh.SetActive (true);
            ddd.SetActive (false);
            levelscored03 += 1;
            totalscored03 += 100; 
            getpoint.Play ();
        }
       if (score01 == 4) {

            hhh.SetActive (true);
            ddd.SetActive (false);
            levelscored03 += 1;
            totalscored03 += 100;  
            getpoint.Play ();
        }


        }

You can’t highlight or use UBB inside code sections.

What’s up with the formatting? You’ve got brackets in weird places, the update method has nothing in it, apparently. Does this even compile or are you just cutting chunks from your script and not pasting it here correctly?

2 Likes

Please describe what you specifically mean by “don’t work.” Don’t make other forum users guess what your problem is, when you certainly know or you wouldn’t be here.

Also, just a pet peeve of mine… In the programming world the word “code” is already plural and can refer to anything from a single line of code to all the code in an entire project. The word “codes” in programming doesn’t make any sense, unless you’re talking about cheat codes or similar.

3 Likes

First, start by formatting your code. The actual problem with your scripts will be blatantly obvious once it’s no longer a colossal mess. Second, count all your braces and semi-colons. Especially when you copy and paste scripts. Copying or forgetting additional braces is a very common mistake.

2 Likes

That’s why brace and semi-colon are unnecessary evil left over :smile:

1 Like

Formatting is not the problem . There is no error in mono develop . But I organized codes ( by formatting document ) and problem doesn’t fix .
For more explanation : When I touch aaa so act002b happens . When I touch fff so act004b happens .When I touch ddd so act001b happens . But when I touch ggg or eee , nothing happens.
When score01 == 2 codes in braces work . But when score01 == 4 nothing happens.
All of this codes work in another script in one game ( not in another game ) !!

WTF?

void Update ()  {
    
        }
1 Like

:smile:
It is ok in my script . It happened at copy time .

But I think find the problem .
Problem is related to one of moving GameObject . Its code ruin codes come after that .
thank all of you . And I will share if I can’t fix it .

so you gave us something completely different than you have and you expect that we magically know what’s wrong with your code which is unseen by us? Neat.

BTW, do you have collider on the game objects you have problems with?

4 Likes

Yes . It has collider . My script has 350 lines . So I copied some important .
I think I can fix it .
Thanks again

Please put a reasonable amount of effort into posts if you expect someone else to put a reasonable amount of time into helping you. Posting broken scripts is a waste of everyones time.

3 Likes

Also, if you call your gameobjects “eee”, your variables “ddd”, your functions “act004b”, and otherwise make your code as esoteric as possible, nobody will be able to help you with it. You will also just end up confusing yourself.

1 Like