Hi there, I’m trying to constantly show a debug.log of a health of a gameobject, but the update function is only called once and not every frame, do you know why?
void Update() // only being called once, why?
{
Debug.Log(Hitpoints); // only shows up once at the start
if (Hitpoints <= MaxHitPoints / 2) // doesn't show up
{
Debug.Log("enemySpawned");
point3.SetActive(true);
point2.SetActive(true);
point1.SetActive(true);
point4.SetActive(true);
}
}
I tried what you said, the scripts are loaded, the game object isn’t turned off, and the editor isn’t paused either because the player and other scripts also work fine, I also didn’t find any errors in the console. Interestingly, I created an another script, this one’s update function doesn’t work as well!! Please HELP !
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlightWarden : MonoBehaviour
{
private BlightBehaviours blightBehaviours;
private bool CallAbility = true;
public float AbilityCoolDown;
public GameObject DroidHanger1;
public GameObject DroidHanger2;
public GameObject DroidHanger3;
public GameObject DroidHanger4;
private float AbilityPhase =1f;
private float WardenHealth;
void Start()
{
blightBehaviours = this.gameObject.GetComponent<BlightBehaviours>();
}
// Update is called once per frame
void Update()
{
WardenHealth = blightBehaviours.Hitpoints;
Debug.Log("Warden Health" +WardenHealth) ; // not being called either??!!!
if(WardenHealth<= 10 && CallAbility == true)
{
Debug.Log("Ablility Called");
CallAbility = false;
ShadowRemake();
}
}
void ShadowRemake()
{
if (AbilityPhase == 1)
{
DroidHanger1.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
else if( AbilityPhase == 2)
{
DroidHanger2.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
else if(AbilityPhase == 3)
{
DroidHanger3.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
else if(AbilityPhase == 4)
{
DroidHanger4.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
}
private IEnumerator ShadowRemakeCoolDown()
{
AbilityPhase++;
yield return new WaitForSeconds(AbilityCoolDown);
ShadowRemake();
}
}
I tried what you said, the scripts are loaded, the game object isn’t turned off, and the editor isn’t paused either because the player and other scripts also work fine, I also didn’t find any errors in the console. Interestingly, I created an another script, this one’s update function doesn’t work as well!! Please HELP !
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlightWarden : MonoBehaviour
{
private BlightBehaviours blightBehaviours;
private bool CallAbility = true;
public float AbilityCoolDown;
public GameObject DroidHanger1;
public GameObject DroidHanger2;
public GameObject DroidHanger3;
public GameObject DroidHanger4;
private float AbilityPhase =1f;
private float WardenHealth;
void Start()
{
blightBehaviours = this.gameObject.GetComponent<BlightBehaviours>();
}
// Update is called once per frame
void Update()
{
WardenHealth = blightBehaviours.Hitpoints;
Debug.Log("Warden Health" +WardenHealth) ; // not being called either??!!!
if(WardenHealth<= 10 && CallAbility == true)
{
Debug.Log("Ablility Called");
CallAbility = false;
ShadowRemake();
}
}
void ShadowRemake()
{
if (AbilityPhase == 1)
{
DroidHanger1.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
else if( AbilityPhase == 2)
{
DroidHanger2.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
else if(AbilityPhase == 3)
{
DroidHanger3.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
else if(AbilityPhase == 4)
{
DroidHanger4.SetActive(true);
StartCoroutine(ShadowRemakeCoolDown());
}
}
private IEnumerator ShadowRemakeCoolDown()
{
AbilityPhase++;
yield return new WaitForSeconds(AbilityCoolDown);
ShadowRemake();
}
}
I have added the debug.log at the beginning and it still doesn’t show up more than once at the beginning. I have tripled checked all the things you said, and they are normal. The update still doesn’t work. Should i submit a bug report?
I also tried creating a new script with only a debug.log and this one only shows up only once as well. This has been happening to every script I have created after 6/22/2021. I think it may be a bug.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Debug.Log("Hello World"); // still only called once for some reason
}
}