- Home /
Update Stopped Working
Updated with scripts, sorry it's long, I don't know what's causing the issue, so figured I'd include it all.
- Yes I have looked through the forums!
My console messages ARE expanded
I have Debug.Log("Test") in Update, it is NEVER called
The Update was working fine for a few hours, then just stopped.
I deleted everything else in the Update and just tried it with the Debug.Log and it does nothing.
Are there any ever exceptions that would cause Update to not work? The only thing I can think of is that this is a base class (Creatures.cs, and then there's another class that uses this as the 'base' class (sorry not a programmer, so technical terms might be off)).
Base Class
using UnityEngine;
using System.Collections;
public class Creature : MonoBehaviour {
//Variables Hidden
void Awake(){
//burningFX = GameObject.Find (this.transform.name + "/CondiFX_Burning");
burningFX = transform.Find("CondiFX_Burning").gameObject as GameObject;
chilledFX = transform.Find ("CondiFX_Chilled").gameObject as GameObject;
poisonedFX = transform.Find ("CondiFX_Poisoned").gameObject as GameObject;
bleedingFX = transform.Find ("CondiFX_Bleeding").gameObject as GameObject;
}
void Update(){
Debug.Log ("Updaaaate"); //This isn't called!
if (burningTime > 0.01f){
burningTime -= Time.deltaTime;
} else if (burningTime <= 0.01f){
burningTime = 0f;
burningFX.SetActive (false);
CancelInvoke("ApplyBurning");
}
if (chilledTime > 0.01f){
chilledTime -= Time.deltaTime;
} else if (chilledTime <= 0.01f){
chilledTime = 0f;
chilledFX.SetActive (false);
CancelInvoke("ApplyChilled");
}
if (poisonedTime > 0.01f){
Debug.Log ("7: Poison has time on it");
poisonedTime -= Time.deltaTime;
} else if (poisonedTime <= 0.01f){
poisonedTime = 0f;
poisonedFX.SetActive (false);
CancelInvoke("ApplyPoisoned");
}
if(bleedingTime > 0.01f){
bleedingTime -= Time.deltaTime;
} else if(bleedingTime <= 0.01f){
bleedingTime = 0f;
bleedingFX.SetActive (false);
CancelInvoke("ApplyBleeding");
}
}
//Called to add or remove health from the current health total
public void AdjustCurHP(float healthAdjustment){
if(curHP > 0)
curHP += healthAdjustment;
}
//Apply Conditions, requires a condition and duration parameter. Sets total condition time to += duration and activates the visual FX
public void ApplyCondition(string condition, float duration){
if(condition == "burning"){
burningTime += duration;
burningFX.SetActive(true);
if(!IsInvoking("ApplyBurning"))
InvokeRepeating("ApplyBurning", 0f, 1f);
} else if (condition == "chilled"){
chilledTime += duration;
chilledFX.SetActive(true);
if(!IsInvoking("ApplyChilled"))
InvokeRepeating("ApplyChilled", 0f, 1f);
} else if (condition == "poisoned"){
poisonedTime += duration;
poisonedFX.SetActive(true);
if(!IsInvoking("ApplyPoisoned"))
InvokeRepeating("ApplyPoisoned", 0f, 1f);
} else if (condition == "bleeding"){
bleedingTime += duration;
bleedingFX.SetActive (true);
if(!IsInvoking("ApplyBleeding"))
InvokeRepeating("ApplyBleeding", 0f, 1f);
}
}
//Invoked to repeat damage at tick intervals
void ApplyBurning(){
AdjustCurHP(-burningDMG);
}
void ApplyChilled(){
AdjustCurHP(-chilledDMG);
}
void ApplyPoisoned(){
AdjustCurHP(-poisonedDMG);
}
void ApplyBleeding(){
AdjustCurHP(-bleedingDMG);
}
}
Inherited Class
using UnityEngine;
using System.Collections;
public class SnowStatus : Creature {
private float guiHPBarLength = 0f;
private float screenH = 0;
private float screenW = 0;
private bool dead = false;
void Start(){
guiHPBarLength = ((Screen.width/2) * (curHP/maxHP));
screenW = Screen.width;
screenH = Screen.height;
}
void Update(){
if (curHP > 0){
guiHPBarLength = ((Screen.width / 2) * (curHP / maxHP));
} else {
guiHPBarLength = 0;
Death();
}
}
void Death(){
SnowTPCon snowController = this.GetComponent ("SnowTPCon") as SnowTPCon;
SnowTPCam snowCam = Camera.main.GetComponent ("SnowTPCam") as SnowTPCam;
snowController.charControlled = false;
snowCam.camFreeze = true;
dead = true;
}
Is your game object the script attached to disabled? Since this is the base class, is this class derived from $$anonymous$$onobehaviour? Providing your script...even if it is just a few lines long...may be helpful in figuring out what is going on.
Sorry about not having the script. I added it now. The game object is definitely enabled. Other variables are being modified from other methods, just the Update is not working.
No, just the Inherited class is attached to the game Object.
Nice, thank you! :) Excited to learn some new things. I haven't worked with inherited classes before, so this is a learning experience!
Answer by deltamish · Feb 25, 2014 at 05:47 AM
Ahh. Since you are inherting a class other than monobehavior Update doesnt get called
MonoBehaviour calls the update function so you might wanna inherit fom that
If you have no idea what i am talking about
please do post your script
EG
public class Class1:BaseClass // as you can seee it is inheriting from Base calss
{
void Update() //Does not get called
{
}
}
Using Mono as base class
public class Class1:MonoBehaviour // as you can seee it is inheriting from Moni class
{
void Update() //Does get called
{
}
}
Base Class
public class BaseClass:MonoBehaviour // as you can seee it is inheriting from Base calss
{
public string MyName;
public virtual void MyUpdate() //Changes the name from Update to MyUpdate for better Understanding the realtionship
{
Debug.Log("Hello" + MyName);
}
}
Okay as you can see that Class1 is inheriting from Base Class For now Think of Inheriting as Using as in terms of using varialbes in Parent class (in this case Base class)
Now if you attach the Class1 to game Object Class1 can acess all methods and variables of BaseClass.
So what you could do is
Class1
public class Class1:BaseClass // as you can seee it is inheriting from Base calss
{
public Class1
:
MyName = " Bill Gates "; // As you can see you can acess the variable from Base Calss
// Now lets call the Methoid of Base calss as you can see her you can directly acees the function
MyUpdate();
}
void Start()
{
// Here you need to base.MyUpdate
base.MyUpdate();
}
}
Hope You understood What i am trying to explain.If you have any doubts just ask.
What's happening to $$anonymous$$e is opposite.
Base Class (Creatures : $$anonymous$$onoBehaviour) is the update that isn't working and (Player : Creature) IS working.
Let me update my question with some code, maybe that will help!
If you want to do it by hand, you can call the base class Update() from the inherited class.
Robertbu - It seems that if your base class and inherited class both have Updates, then the inherited class overrides the base class.
If just your base class has it then your inherited class automatically runs the base class Update.
Everything makes sense, just a question on the last part.
void Start(){
base.$$anonymous$$yUpdate();
}
For this part, base is referring to the base class, I'm assu$$anonymous$$g, and $$anonymous$$yUpdate means it 'grabs' the update from that base class.
Could I then extend the Update in the Inherited class, or is it only able to copy directly the base Update?
Going to do some research on this so I know better as well. I really appreciate the help!
Sorry i gues i wasmt clear. Here base doesnt refer to Base Class It Just refers to the Parent Class. Lets Say the ParentClass is $$anonymous$$yNewParentClass and it has a function called GetInfo
Then in the iherited script you could acess it by using
base.GetInfo();
Could I then extend the Update in the Inherited class, or is it only able to copy directly the base Update?
Yes of cource you can extend your Update Function in order to call the prent class method you have to use base.Update(); or base.Start(); for Start like that
If you have further doubts post them here i will lokk into it once i get back
am gonna Leave now.Need to study *