|
Post by wohltaeter on Mar 21, 2016 14:20:07 GMT
Hi, the core game kit is a very helpful tool but I am stuck with realizing a virtual bomb that kills all enemies on the screen. - I have already a solution with a gamecontroller by pressing the 'b' key but I wonder how to realise it with the core game kit. Where can I hook in the getKey 'b' and where can I update the the Worldvariable with -1? - Also where should I put the Killable on when the bomb itself is only virtually - as I understood I would need one. - Also I tried to update the world variable for the Bombs in the script but it does not update, I can read but not write. Only my old variable from the game controller is updating. I can see the World Var with a listener. - Here is the code from my gamecontroller:
private int bomb;//not the worldvariable
void Update ()
{
var variable = WorldVariableTracker.GetWorldVariable("Bombs"); //the world variable bomb = variable.CurrentIntValue; // my var can read
if (Input.GetKeyDown (KeyCode.B) && bomb > 0) {
BombeSchmeissen ();
bomb--;
bombText.text = "Bomben: " + bomb;
variable.CurrentIntValue -= 1; // does not update } public void BombeSchmeissen () { // Releases the Bomb
if (bomb > 0) {
enemies = GameObject.FindGameObjectsWithTag ("Enemy");
Instantiate (bombenExplosion);
foreach (var enemie in enemies) {
Destroy (enemie);
}
}
Would be great to hear the solution.
Cheers
|
|
|
Post by DarkTonic Dev on Mar 21, 2016 19:25:26 GMT
Probably you can't set the CurrentIntValue because you are trying to set it to a negative value. There's a checkbox "Allow negative" in the Inspector where you set up the World Variable. I'm guessing that it isn't checked (that's the default) so it's silently failing. Does it work if you try and set the CurrentIntValue to a positive number?
You can put the key detection code anywhere you like, as you have. I'm not sure if you have any other questions?
Also, I see that you're destroying the game objects of your enemies. That isn't allowed since everything in CGK uses Pool Boss, which pools objects. Destroying means you are no longer pooling and will have worse performance, and Pool Boss will have errors the next time it tried to use the destroyed object.
You should be despawning things instead of destroying them.
Also, if your enemies are using Killable, you will want to call the DestroyKillable method on the Killable component instead so it can use the death prefab (i.e. explosion), modify any World Variables set up there and it will automatically despawn as well.
|
|
|
Post by wohltaeter on Mar 22, 2016 12:20:38 GMT
Thanks for the quick reply! - It helped to find the problem. - I also fixed destroying.
|
|
|
Post by DarkTonic Dev on Mar 22, 2016 15:38:21 GMT
No problem.
|
|