Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
Debug.Log being delayed in Unity

While trying to create a game in Unity about you building a small city I stumbled upon a problem. I'm using NavMesh to have the player lead around tiny people (called mixxes here). The NavMesh is working, just I'm trying to make the mixxes produce different materials based on the location you lead them to.

Here is my code so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class MixxScript : MonoBehaviour
{
    public float speed = 5f;
    public Transform target = null;

    public Transform oldTarget = null;

    public Transform lastPossibleSuccess;

    public float range = 8.4f;
    public NavMeshAgent agent;
    private float countdown = 3;

    void Update()
    {
       if (target == null)
       {
            return;
       }
        agent.SetDestination(target.position);
        float distance = Vector3.Distance(transform.position, target.position);
        Debug.Log(distance);
        if (distance <= 2)
        {
            countdown -= Time.deltaTime;
            if (countdown <= 0)
            {
                if (target.transform.name == "Factory")
                {
                    MainScript.metal += 1;
                }
                if (target.transform.name == "Farm")
                {
                    MainScript.food += 1;
                }
                countdown = 3;
            }
        }
        else
        {
            countdown = 3;
        }

    }
    void OnMouseDown()
    {
        MainScript.selectedMixx = gameObject;
       
    }
}

And here is MainScript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MainScript: MonoBehaviour
{

    public static GameObject selectedMixx = null;
    public static GameObject selectedPlatform = null;

    public static float metal = 0;
    public static float wood = 0;
    public static float money = 0;
    public static float mixxes = 1;
    public static float food = 50;

    public Text scoreText;

    void Update()
    {
        scoreText.text = "Money: $" + money.ToString() + "\nFood: " + food.ToString() + "\nMetal: " + metal.ToString() + "\nWood: " + wood.ToString() + "\nMixxes: " + mixxes.ToString();

    }


}

The problem is that 1) The text as shown in MainScript is not updating. 2) The Debug.Log() statement is not working so I cannot see what is wrong here.

What I've tried:

  • Multiple ways to measure distance
  • Different distance restraints (such as the one on line 28 of the first script)
  • Using FixedUpdate() instead of Update() (which failed completely)

Is there a solution to this?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda