Skip to main content
formatting, tags
Source Link
Kevin
  • 7k
  • 1
  • 12
  • 32

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;

using UnityEngine;

public class Flags : MonoBehaviour { public GameObject[] SoldierOfFlag; public bool[] DiedTF = new bool[7];

using UnityEngine;

public class Flags : MonoBehaviour
{
    public GameObject[] SoldierOfFlag;
    public bool[] DiedTF = new bool[7];

    private WaitForSeconds HalfASecond = new WaitForSeconds(0.5f);

    void Start()
    {
        StartCoroutine(SoldierDeadRegistrationCor());
    }

    IEnumerator SoldierDeadRegistrationCor()
    {
        while (true)
        {
            yield return HalfASecond;

            for (int i = 0; i < 7; i++)
            {
                if (SoldierOfFlag[i].GetComponent<BlueSoldiersScript>().Soldier.SoldierLife <= 0 && !DiedTF[i])
                {
                    DiedTF[i] = true;
                }
            }
        }
    }
}

}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;

using UnityEngine;

public class Flags : MonoBehaviour { public GameObject[] SoldierOfFlag; public bool[] DiedTF = new bool[7];

private WaitForSeconds HalfASecond = new WaitForSeconds(0.5f);

void Start()
{
    StartCoroutine(SoldierDeadRegistrationCor());
}

IEnumerator SoldierDeadRegistrationCor()
{
    while (true)
    {
        yield return HalfASecond;

        for (int i = 0; i < 7; i++)
        {
            if (SoldierOfFlag[i].GetComponent<BlueSoldiersScript>().Soldier.SoldierLife <= 0 && !DiedTF[i])
            {
                DiedTF[i] = true;
            }
        }
    }
}

}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;
using UnityEngine;

public class Flags : MonoBehaviour
{
    public GameObject[] SoldierOfFlag;
    public bool[] DiedTF = new bool[7];

    private WaitForSeconds HalfASecond = new WaitForSeconds(0.5f);

    void Start()
    {
        StartCoroutine(SoldierDeadRegistrationCor());
    }

    IEnumerator SoldierDeadRegistrationCor()
    {
        while (true)
        {
            yield return HalfASecond;

            for (int i = 0; i < 7; i++)
            {
                if (SoldierOfFlag[i].GetComponent<BlueSoldiersScript>().Soldier.SoldierLife <= 0 && !DiedTF[i])
                {
                    DiedTF[i] = true;
                }
            }
        }
    }
}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.

deleted 19 characters in body
Source Link

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;

using UnityEngine;

public class TotemlerFlags : MonoBehaviour { public GameObject[] TotemKoruyanlar;SoldierOfFlag; public bool[] DirilmeTFDiedTF = new bool[7];

private WaitForSeconds YarimSaniyeBeklemeHalfASecond = new WaitForSeconds(0.5f);

void Start()
{
    StartCoroutine(TotemTakasDongu2CorSoldierDeadRegistrationCor());
}

IEnumerator TotemTakasDongu2CorSoldierDeadRegistrationCor()
{
    while (true)
    {
        yield return YarimSaniyeBekleme;HalfASecond;

        for (int i = 0; i < 7; i++)
        {
            if (TotemKoruyanlar[i]SoldierOfFlag[i].GetComponent<MaviDusmanlarScript>GetComponent<BlueSoldiersScript>().DusmanMSoldier.hayvancanSoldierLife <= 0 && !DirilmeTF[i]DiedTF[i])
            {
                DirilmeTF[i]DiedTF[i] = true;
            }
        }
    }
}

}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;

using UnityEngine;

public class Totemler : MonoBehaviour { public GameObject[] TotemKoruyanlar; public bool[] DirilmeTF = new bool[7];

private WaitForSeconds YarimSaniyeBekleme = new WaitForSeconds(0.5f);

void Start()
{
    StartCoroutine(TotemTakasDongu2Cor());
}

IEnumerator TotemTakasDongu2Cor()
{
    while (true)
    {
        yield return YarimSaniyeBekleme;

        for (int i = 0; i < 7; i++)
        {
            if (TotemKoruyanlar[i].GetComponent<MaviDusmanlarScript>().DusmanM.hayvancan <= 0 && !DirilmeTF[i])
            {
                DirilmeTF[i] = true;
            }
        }
    }
}

}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;

using UnityEngine;

public class Flags : MonoBehaviour { public GameObject[] SoldierOfFlag; public bool[] DiedTF = new bool[7];

private WaitForSeconds HalfASecond = new WaitForSeconds(0.5f);

void Start()
{
    StartCoroutine(SoldierDeadRegistrationCor());
}

IEnumerator SoldierDeadRegistrationCor()
{
    while (true)
    {
        yield return HalfASecond;

        for (int i = 0; i < 7; i++)
        {
            if (SoldierOfFlag[i].GetComponent<BlueSoldiersScript>().Soldier.SoldierLife <= 0 && !DiedTF[i])
            {
                DiedTF[i] = true;
            }
        }
    }
}

}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.

Source Link

Why doesn't Coroutine work the way I want with if blocks?

I'm making a game and when the enemy dies I keep it in memory. I want the person playing to find the game just as they left it when they enter. I'm doing most of these, but there's one small problem left. The problem is, when I write the if block code line in Fixed update, I get the value true when the enemy dies and the true tick is activated in the inspector, but when I want to do this with the coroutine, I cannot activate it. In general, I had trouble using Coroutine with if blocks while making the game. If anyone knows where the problem is, I would be very happy if they could help. How should I revise this code? Where is the mistake?

I call this coroutine at start

using System.Collections;

using UnityEngine;

public class Totemler : MonoBehaviour { public GameObject[] TotemKoruyanlar; public bool[] DirilmeTF = new bool[7];

private WaitForSeconds YarimSaniyeBekleme = new WaitForSeconds(0.5f);

void Start()
{
    StartCoroutine(TotemTakasDongu2Cor());
}

IEnumerator TotemTakasDongu2Cor()
{
    while (true)
    {
        yield return YarimSaniyeBekleme;

        for (int i = 0; i < 7; i++)
        {
            if (TotemKoruyanlar[i].GetComponent<MaviDusmanlarScript>().DusmanM.hayvancan <= 0 && !DirilmeTF[i])
            {
                DirilmeTF[i] = true;
            }
        }
    }
}

}

This is enemy soldier

This is enemy soldier

These are the bool values ​​in the inspector window that I expect to be active.

Bool values

In the screenshot here, the enemy soldier dies, but the bool value does not change.

In the screenshot here, the enemy soldier dies, but the bool value does not change.