An if function doesnt work properly

I dont know if this is th right place for it, but I have problems with this script i wrote for the new boss in my videogame. The boss is supposed to grow bigger when he appears, then show a question if you want to spear him because he is so adorable and if you choose no, the fight starts. The attack is choosen by a random number, if its 1 the following attack is triggered. first the boss is getting smaller until you cant see him anymore then a bool is set to false so it stops getting samller and another is set to true so the teleporting is started, that teleports the boss to a random location. then the bool thing is triggered again and the growing back to its old size is starting. Excuse the german names of the variables and my bad english and if this is in the wrong place. Thank you.
With the help of the comments i figuered out that an if function is working even if its statement is wrong. what is wrong?
here is the script

i dont know why this isnt working

using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;

public class hamstisskripti : MonoBehaviour
{
    public Spieler player;
    public bool start;
    public float displaytime;
    public float eins;
    public float zwei;
    public bool ja;
    public Vector3 neu;
    public float timer1;
    public float weiter1;
    public int zufall;
    public bool passiert;
    public GameObject willstdu;
    public bool oins;
    public bool zwoi;
    public bool droi;
    public bool nuul;
    public int x;
    public int y;
    
    // Start is called before the first frame update
    void Start()
    {
        ja = false;
        start = true;
        passiert = false;
        player = GameObject.FindWithTag("player").GetComponent<Spieler>();
        displaytime = 5f;
        weiter1 = 10;
        oins = false;
        zwoi = false;
        droi = false;
        nuul = false;
        
    }

    // Update is called once per frame
    void Update()
    {
        if (player.spielen == true)
        {
            if (start == true)
            {
                if (gameObject.transform.localScale.x <= 0.4f)
                {
                    neu = new Vector3(0.0001f, 0.0001f, 0.0001f);
                    transform.localScale += neu;
                    
                }
                else
                {
                    start = false;
                    willstdu.SetActive(true);
                }
            }
            if (start == false)
            {
                if (ja == true)
                {
                    if (timer1 < weiter1)
                    {
                        timer1 = timer1 + Time.deltaTime;
                    }
                    else
                    {
                        timer1 = 0;
                        zufall =Random.Range(1, 4);
                        passiert = false;
                    }
                    if (zufall == 1)
                    {
                        if (gameObject.transform.localScale.x >= 0f && nuul==true)
                        {
                            neu = new Vector3(0.0001f, 0.0001f, 0.0001f);
                            transform.localScale -= neu;
                            
                        }
                        else
                        {
                            nuul = false;
                            oins = true;
                            
                        }
                        if (oins == true)
                        {
                            oins = false;
                            Debug.Log("teleportiert");
                            x = Random.Range(-8, 8);
                            y = Random.Range(-4, 4);
                            transform.position = new Vector3(x, y, 0);
                            oins = false;
                            zwoi = true;
                        }
                        if (zwoi == true)
                        {
                            Debug.Log("starte wachstum");
                            if (gameObject.transform.localScale.x <= 0.4f)
                            {
                                Debug.Log("amwachsen");
                                neu = new Vector3(0.00000001f, 0.00000001f, 0.00000001f);
                                transform.localScale += neu;

                            }
                            else
                            {
                                zwoi = false;
                            }
                        }
                        
                    }
                }
            }
        }

    }
    public void verschonen()
    {
        player.troll = false;
        player.hamsti = true;
        willstdu.SetActive(false);
        if (gameObject.transform.localScale.x <= 0f)
        {
            neu = new Vector3(0.0001f, 0.0001f, 0.0001f);
            transform.localScale -= neu;

        }
        this.gameObject.SetActive(false);
    }
    public void nichtverschonen()
    {
        ja = true;
        willstdu.SetActive(false);
    }
    public IEnumerator größern()
    {
        
        yield return new WaitForSeconds(displaytime);
        neu = new Vector3(0.001f, 0.001f, 0.001f);
        transform.localScale += neu;
    }
}

Well i don’t understand deutsch and this is pretty huge chunk. So i only suggest giving it to Google Gemini or something to ask for fix, some foundable 2.0 even gave me fully back my script with 642 lines of code 20 of which is new feature i asked to add and it worked first try, considering it wasn’t even Unity and database was even worse.

If you have compiler errors, fix them.

If it does not function properly, debug the code.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

When you work, always build one step at a time. Do NOT move onto the next step until each step works.

Imphenzia: How Did I Learn To Make Games:

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

1 Like

i tried solving my problem this way but it just wont stop teleporting although the variable that allows that int the if statement is false

i tried it but it has not worked

OK so specifically which statement isnt working and did you debug all the variables to show state at the time?

1 Like

Then you indeed need to debug (which most people suggest) and think your own solution.

Though you still can try asking AI more properly (do not use dumb one’s like ChatGPT 3.5) like “(thing) not working, debug and tell why” e.t.c or use it in the middle to come to the solution quicker.

~(“(problematic code part)
(issue). List of all what’s wrong with this code”).

If code is quite specific (and has bad readability, convention) it probably won’t guess properly just by giving it with
~"(code)

debug".

Btw, AI can act as a JavaScript console (so it will show bugs also?), but dunno about Unity C#.
Potentially AI can be used as a separate debugger, but manual work is still more robust and less error prone, though slower in many situations.

Tbh, if i read all properly and understood deutsch maybe i’d already solve this one with AI assist, with a little more time, instead of replies. (though not guaranteed)

thank you all for your help, I finally found the failure. It was else function which constantly set a variable to true which was supposed to be false, seems like i have to train my debugging skills

1 Like

It’s all good… after 40+ years of debugging, I am still training my debugging skills. It never stops.

1 Like