H
H
hana012021-05-09 18:36:18
Unity
hana01, 2021-05-09 18:36:18

Why doesn't the same code work?

There are two parts of the code, almost exactly the same: only the names of the buttons and the location of the camera differ, the structure and algorithms are the same, but one part works, the other does not. What can be wrong?
One part:

One part
case 1:
            cam = GetComponent<Camera>();
           cam.orthographicSize = 8;
            this.transform.position = new Vector3(0,25,-10);
            LocationButton = new Rect(new Vector2(ScreenCenter_X-200,0), new Vector2(250,190));
           GUI.Box(LocationButton,"");
           LocationButton = new Rect(new Vector2(ScreenCenter_X-85, 10), new Vector2(200,30));
           GUI.Label(LocationButton,"Док");
           LocationButton = new Rect(new Vector2(ScreenCenter_X-170, 50), new Vector2(200,30));
            if(GUI.Button(LocationButton,"Вернуться в меню")){
               PlayerPoleControl.Clear();
               GameMode=0;
           }
           LocationButton = new Rect(new Vector2(ScreenCenter_X-170, 90), new Vector2(200,30));
            if(GUI.Button(LocationButton,"Разместить флот")){
               PlayerPoleControl.randomShips();
           }
           if(PlayerPoleControl.LifeShip()==20){
               LocationButton = new Rect(new Vector2(ScreenCenter_X-170, 130), new Vector2(200,30));
               if(GUI.Button(LocationButton,"В бой")) {
                   if(WhoPlayMode==1){
                       GameMode=2;
                   Player.GetComponent<GameField>().CopyMap();
                   Computer.GetComponent<GameField>().randomShips();
                   } 
               }
           }
            break;


Other part:
Other part
cam = GetComponent<Camera>();
            cam.orthographicSize = 8;
            this.transform.position = new Vector3(48,27,-10);
            LocationButton = new Rect(new Vector2(ScreenCenter_X-200,0), new Vector2(250,190));
           GUI.Box(LocationButton,"");
           LocationButton = new Rect(new Vector2(ScreenCenter_X-120, 10), new Vector2(200,30));
           GUI.Label(LocationButton,"Первый игрок");
           LocationButton = new Rect(new Vector2(ScreenCenter_X-170, 50), new Vector2(200,30));
            if(GUI.Button(LocationButton,"Вернуться в меню")){
               PlayerPoleControl.Clear();
               GameMode=0;
           }
           LocationButton = new Rect(new Vector2(ScreenCenter_X-170, 90), new Vector2(200,30));
            if(GUI.Button(LocationButton,"Разместить флот1 ")){
               PlayerPoleControl.randomShips();
           }
           if(PlayerPoleControl.LifeShip()==20){
               LocationButton = new Rect(new Vector2(ScreenCenter_X-170, 130), new Vector2(200,30));
               if(GUI.Button(LocationButton,"В бой!")) {
                   Player.GetComponent<GameField>().CopyMap();
               }
           }
            break;


Here is what happens in the first case:
before pressing the button for placing ships: (the line next to the field is an indicator of the number of decks placed, it should be 20 pieces: red - there is no deck (destroyed), green - the deck is alive)
A photo
60980084322d7241877442.png


after pressing:
A photo
60980090bb6bd296664668.png


Here's what happens in the second case:
before the ship placement button:
A photo
609800a2cdada535367737.png


after:

A photo
609800afbee84682052654.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kachan, 2021-05-12
@MANAB

In the second case, there is no call to Computer.GetComponent().randomShips();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question