|
Post by benezuvys on Apr 11, 2018 3:34:30 GMT
Why I have empty value ?
public Killable killable;
private void Awake() { killable = GetComponent<Killable>();
startingHealth = killable.CurrentHitPoints;
currentHealth = startingHealth;
Debug.Log("CurrentHealth: " + currentHealth); }
|
|
DarkTonic Dev
Administrator
Posts: 4,384
Posts: 4,384
Member is Online
|
Post by DarkTonic Dev on Apr 11, 2018 4:11:01 GMT
Awake may run before the Killable has done anything? I would try Start. Well, you can cache the Killable component itself in Awake, but I'd try to read it in Start or later. Anyway, CurrentHitPoints is an non-nullable integer so it can't be "no value". It could be zero if you called too early. What's in the Console?
|
|
|
Post by benezuvys on Apr 11, 2018 4:25:49 GMT
Thanks! In the Console was 0, but after recode in Start() everything is working.
I can do that? But Killable destroys my object before СurrentHealth == 0, why?
currentHealth -= damageTaken; Debug.Log("After Damage: " + currentHealth); killable.TakeDamage((int)damageTaken);
|
|
DarkTonic Dev
Administrator
Posts: 4,384
Posts: 4,384
Member is Online
|
Post by DarkTonic Dev on Apr 11, 2018 6:02:38 GMT
Does the takeDamage call kill it? What should it's current hit points be after taking that damage?
|
|
|
Post by benezuvys on Apr 11, 2018 6:40:41 GMT
I have damage from another script. That the Killable understood that he died transfer damage in Killable ("TakeDamage" Call this method to inflict X points of damage to a Killable) and then he get me LIVES -1. lol.
|
|
DarkTonic Dev
Administrator
Posts: 4,384
Posts: 4,384
Member is Online
|
Post by DarkTonic Dev on Apr 11, 2018 15:04:13 GMT
That all sounds like it's working properly, no?
|
|
|
Post by benezuvys on Apr 12, 2018 3:19:16 GMT
No, the Killable destroys object by collision earlier than Health == 0. Why? When Layer and Tag filters == null.
|
|
DarkTonic Dev
Administrator
Posts: 4,384
Posts: 4,384
Member is Online
|
Post by DarkTonic Dev on Apr 12, 2018 3:53:24 GMT
The only way that will happen is if you have changed a certain setting on the Killable. It's not the default. Open the "Despawn & Death Triggers" section and see if you have "HP Death Mode" set to something different than "Zero Hit Points". The 2nd and 3rd choice would make it die early.
If you have the default there, then turn on Log Events for the Killable and see if any hint is given in the Console when it dies.
|
|
|
Post by benezuvys on Apr 12, 2018 7:25:43 GMT
And how do me work with WorldVariables, so that i can record events in world? e.g. if (Lives == 0) { GameOver } or get Score, Exp after GameOver. Do you have an example of working with this?
|
|
DarkTonic Dev
Administrator
Posts: 4,384
Posts: 4,384
Member is Online
|
Post by DarkTonic Dev on Apr 12, 2018 15:46:38 GMT
The first part looks like you want the game to end when you reach zero lives. That sort of functionality is already built in, you don't have to write code for it. On the World Variable, make sure "Triggers Game Over" is on and you specify the range (like 0-0). In fact that's the default for the Lives variable. For the 2nd part, after or before GameOver doesn't matter, the code is the same to read a World Variable. var variable = WorldVariableTracker.GetWorldVariable("yourVarName"); variable.CurrentIntValue = 45; // or CurrentFloatValue for a float!
I copied that code from the online documentation, you probably should do a quick read so you can get quicker responses than waiting for me. Link below. www.dtdevtools.com/docs/coregamekit/WorldVariables.htm
|
|