Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

274
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda