Search Unity

Core GameKit! Pooling / Spawning / Combat

Discussion in 'Assets and Asset Store' started by jerotas, Jan 27, 2013.

  1. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Well, thank you - asking to re-explain made me figure it out how to do it. ;)
    I've managed to implement perlinnoise randomization and for the mirroring i realized, when i use SpawnOneItem() inside of ItemSpawned(), that the access i need, will be the transform in the next ItemSpawned(). Though it would be nice if SpawnOneItem() could return the spawned transform for reference.
     
    Last edited: Aug 9, 2014
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok, I'll make a note to make it return that Transform in the next version.
    Thanks!
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit V3.2.2.4 will be live in 10 minutes! Changelog:

    • Added Spawn Offset (Vector3) to Damage Prefab section in Killable so it doesn't have to spawn at exactly the same position as the Killable.
    • Added EliminationWaveCompleted method to WaveSyncroSpawnerListener & the Playmaker version . This event is sent every time a syncro spawner elimination wave is completed (all repetitions), before it pauses for wave repeat delay.
    • Added new Playmaker custom actions: Core GameKit Pool Boss Despawn Prefabs Of Type, Core GameKit Pool Boss Kill Prefabs Of Type, Core GameKit Pool Boss Despawn All Prefabs, Core GameKit Pool Boss Kill All Prefabs
    • Added Lose event to LevelSettingsListener and the Playmaker listener as well. This fires if game over is reached and you didn't win (waves not all completed or other trigger).
    • SpawnOneItem() in Syncro Spawner script now returns the spawned transform for reference.
    • Changed the Playmaker custom action Core Game Kit Syncro Spawner Spawn One so that you can assign the item spawned to a variable.
    • Added GotoWave(level#, wave#) in Level Settings. Ends the current wave immediately and spawns that level / wave. Can even go to an earlier level or wave!
    • Added a new Playmaker custom action: Core Game Kit Goto Wave, which does the GotoWave(level#, wave#) action in the bullet above.
     
    Binary42 likes this.
  4. dark_tonic

    dark_tonic

    Joined:
    Mar 23, 2011
    Posts:
    138
  5. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    stupid question: could you add photon support?
     
  6. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    At this point, we'd be more likely to add Bolt support, which is a new beta plugin that does the same sort of thing.
    However, what exactly would adding networking support entail?
     
  7. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
     
  8. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    well simply for the pooling, having the pools initialized by the masterclient, and change the spawn to be photon.instanciate // bolt.instantiate
     
  9. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok, I'm not really sure how any of that works. I've never worked on network stuff before. But I will be soon for our next game, and then I'll probably integrate whichever network plugin we're using because I definitely want pooling in there.

    I heard that Photon has a requirement that prefabs be in a Resources folder, so it might not actually be possible to adapt that one. Bolt has no such requirement though.
     
    Last edited: Aug 15, 2014
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit V3.2.2.5 will be live in 5 minutes. Changelog:

    • Fixed performance bug in Triggered Spawner Inspector. It would constantly refresh the Inspector causing frame drops. No longer!
    • Added Position Settings section to Triggered Spawner. Now you can choose the spawn position (x, y and/or z) to hard-code or read from a World Variable.
    • Added Position Settings section to Syncro Spawner. Now you can choose the spawn position (x, y and/or z) to hard-code or read from a World Variable.
    • Fixed bug where Triggered Spawner was checking wrong variable for active waves for Enable and Disable waves.
    • Added HasActiveWaveOfType method to Triggered Spawner, so you can tell if a wave is already spawning and not trigger it to start over again yet.
    • Added optional Behavior Designer package with 34 tasks - all the Playmaker custom actions are now tasks.
    • Added new Playmaker Custom Actions: Core Game Kit Triggered Spawner Has Wave Type & Core Game Kit Triggered Spawner End Wave
     
  11. Keitaro3660

    Keitaro3660

    Joined:
    May 20, 2014
    Posts:
    86
    OMG, that's really STUPID price, for the one that don't buy it now!
    anyway, is Master Audio will get stupid price too? :p
     
  12. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Probably not. We'll see.
     
  13. garrido86

    garrido86

    Joined:
    Dec 17, 2013
    Posts:
    233
    Thank you for adding the latest Playmaker Actions, especially the GoToWave Action is very Helpful for me!
     
  14. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No problem.
     
  15. garrido86

    garrido86

    Joined:
    Dec 17, 2013
    Posts:
    233
    Is there a way to read the current Wave with Playmaker?
    I would like to iterate the Waves. For example: When we end Wave 10, we go back to Wave 1.
     
  16. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I just added a couple properties to LevelSettings.cs, LevelNumber and WaveNumber.
    These can used with the GetProperty method in Playmaker to read the current level and wave number.

    This will be in the next version.
     
  17. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit V3.2.2.6 will be live in 20 minutes. Changelog:

    • Added LevelNumber and WaveNumber properties to LevelSettings script. These can be used with the GetProperty method in Playmaker to read the current level and wave number.
    • Added checks for missing LevelSettings in scripts so there are no Null Exceptions logged if so.
    • Removed band-aid code for 2D collider Killables to both hurt each other when one dies from a collision.
    • Note: to get the bullet above to still work, go open the Physics 2D screen from Edit -> Project Settings -> Physics2D and turn off the checkbox labeled "Delete Stops Callbacks". This is important because Unity 2D collisions are treated differently by default.
    • No longer calling CoRoutine to destroy Killable unless you have a death delay > 0. Less allocation is always good.
    • Added "Modifications Allowed" dropdown to World Variables. Choices are Any (the default), Only Increase and Only Decrease. This allows you to control whether a variable can be decreased, increased, or neither. For example you might use Only Increase for a High Score variable.
    • Fixed "set World Variable" code so that it triggered Game Over if you have set a Game Over value for the variable and also calls the listener event.
    • Global Waves now should show a row for each spawner in the wave and you can click to go to it.
     
  18. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Announcement: Core GameKit is now fully compatible and tested in Unity 5 beta!

    This update will be in the next version.
     
  19. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit 3.2.2.7 will be live in 10 minutes. Changelog:

    • Some minor adjustments for World Variables for the "high score" variable types in the last version.
    • Changed code to compile and work with Unity 5 beta!
     
  20. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Updated to the latest version and got the following error upon importing:

    Assets/DarkTonic/CoreGameKit/Scripts/Utility/Killable.cs(1126,17): error CS0246:
    The type or namespace name `Rigidbody2D' could not be found. Are you missing a
    using directive or an assembly reference?
     
  21. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You'll need to let me know what version of Unity you're on. I tried in V 3.5.7 and it compiles fine...
     
    Last edited: Sep 6, 2014
  22. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit is on a HUGE sale for $10 (full price is $50). Time to pick it up for the price of a lunch if you haven't already!
     
  23. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    What are the lines of code needed to use the Code-Triggered 1 activation event? I'm used to doing this in PlayMaker, but this time I'm trying to learn C#, I'd like to do as much as I can without PM.
    This is what I'm starting with. I have no idea how to hook this up to the Triggered Spawner Script.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerAttackAbility : MonoBehaviour {
    5.    
    6.  
    7.     // Update is called once per frame
    8.     void Update ()
    9.     {
    10.         if(Input.GetButtonDown ("Attack"))
    11.         {
    12.             Debug.Log ("Shooting Button Down");
    13.             SendMessage("ActivateCodeTriggeredEvent1");
    14.         }
    15.     }
    16.    
    17. }
    18.  
     
    Last edited: Sep 6, 2014
  24. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    What you wrote may work if the TriggeredSpawner is on the same GameObject as your script.
    Do this instead of SendMessage, it's much faster execution:

    Code (CSharp):
    1.  
    2.    var spawner = this.GetComponent<TriggeredSpawner>();
    3.    spawner.ActivateCodeTriggeredEvent1();
    4.  
    Ideally, you would keep that spawner variable inside the class instead of just the method and do the GetComponent part in Awake(), then it doesn't have to execute that line more than once ever (better performance).

    If the Spawner is on a different game object, just put a public variable of type TriggeredSpawner at the top of the script and use it instead of GetComponent.
     
  25. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Okay so this isn't working as I have it. There are no errors, but nothing happens, as well.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerAttackAbility : MonoBehaviour {
    5.  
    6.    
    7.  
    8.     void Awake ()
    9.     {
    10.         if(Input.GetButtonDown ("Attack"))
    11.         {
    12.             Debug.Log ("Shooting Button Down");
    13.             //SendMessage("ActivateCodeTriggeredEvent1");
    14.             var spawner = this.GetComponent<TriggeredSpawner>();
    15.             spawner.ActivateCodeTriggeredEvent1();
    16.         }
    17.         //var spawner = this.GetComponent<TriggeredSpawner>();
    18.         //spawner.ActivateCodeTriggeredEvent1();
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     /*void Update ()
    23.     {
    24.         if(Input.GetButtonDown ("Attack"))
    25.         {
    26.             Debug.Log ("Shooting Button Down");
    27.             SendMessage("ActivateCodeTriggeredEvent1");
    28.         }
    29.     }*/
    30.    
    31. }
    32.  
     
  26. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    This is what I meant to do.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class PlayerAttackAbility : MonoBehaviour {
    4.     private TriggeredSpawner spawner;  
    5.  
    6.     void Awake ()
    7.     {
    8.          spawner = this.GetComponent<TriggeredSpawner>();
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update ()
    13.     {
    14.         if(Input.GetButtonDown ("Attack"))
    15.         {
    16.             Debug.Log ("Shooting Button Down");
    17.             spawner.ActivateCodeTriggeredEvent1();
    18.         }
    19.     }
    20. }
    21.  
     
  27. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Thanks soooo much! I still have a lot to learn about the coding side of Unity.
     
  28. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Cool, glad it's working now :)
     
  29. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    The only thing I've noticed is that it's spawning from the parent and not the child, like I thought I set it up to do. I have it so the Player object has a child. They both have triggered Spawner Scripts, and the Player is propagating to the child. Basically I want the child to spawn the projectile, not the Parent. What am I missing?

    EDIT: I figured it out, thanks to the tutorial vids. I'm happy that even though the techniques are from before 3.0, they still apply.
     
    Last edited: Sep 6, 2014
  30. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    A parent will not use the wave specifics set up in a child prefab if that's what you're saying. It doesn't work that way. You would set up a "wave of zero" in the parent (Code-Triggered wave) if you don't need any parent wave, then set up the real wave in the child (also Code-Triggered) and turn on propagation. On the child spawner did you set "Trigger Source" to "Receive From Parent"? If not, it won't catch the propagated wave at all.

    However if there's only 1 child spawner, I'm not sure why you would want a parent/child setup. Seems like unnecessary complications. Why not just have the parent spawn those things?
     
  31. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    I want to make sure the projectile looks right when it is spawned from the character sprite.
     
  32. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I think you can use the "wave offset" field that was added awhile back if it's a repositioning matter. Child spawner should not be needed unless you have multiple child spawners or some specific weird logic or something.
     
  33. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Okay, what do I do when I want to have 2 to 8 way shooting, then?
     
  34. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You could use the incremental settings for that. Either use spacing and / or rotation there. The "number to spawn" field could be populated from a World Variable and you could use the "keep center" option to spread out the shots equally to left and right sides. Look at "fighter2" in the Triggered Spawner example scene for an example of keep center.

    Note, this will only work if your rotation / spacing is symmetrical and with even rotation / spacing between all projectiles.
     
  35. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    So what I meant was 2 ~ 8 way shooting for a side scrolling of top down shooter. Like Megaman, who shoots left or right. Or in Contra 3 where you can shoot in 8 directions. Does what you suggested still apply?
     
  36. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No, I was talking like Sky Shark or Zanac "fire 5 bullets at once" type of thing. In that case you'll probably need to use code to position the projectile in the right place depending on the direction your character is facing, and rotate it to face that way as well (so a script can simple "go forward" on the projectile). You could make a subclass of the Triggered Spawner script and have nothing in it except code to override the GetSpawnRotation and GetSpawnPosition methods in Triggered Spawner to have your custom logic.
     
  37. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    I am on Unity 3.5.7 Pro on OSX 10.6.8.
     
  38. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ok, I'll double check and fix it in the next version. This won't be a quick fix as I'm in the middle of a large addition right now. So hopefully you can revert back to the last working version while you wait.
     
  39. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Ok so I'm working to implement the ability for the player to shoot left and right. The problem is that the projectiles are not always going in the right direction. Since they're being recycled, they seem to be remembering which direction they were set to move in when they were initially activated. How can I make it move in the correct direction?

    This is what I have so far
     
  40. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Looks like your logic in OnEnable is wrong. That will run every time the object is re-activated, but it will only reverse the direction if you're facing right, and yes that will be only reversing what the last maxSpeed was. That's not what you want to do. Something like that following should work in OnEnable. Although truly, it's more correct to put this code in OnSpawned instead of OnEnable.

    if(!playerscript.facingRight) {
    arrowMaxSpeed = new Vector2(-500, 0); // make 2 variables for these vectors, like goRightSpeed and goLeftSpeed.
    } else {
    arrowMaxSpeed = new Vector2(500, 0);
    }
     
  41. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit V 3.2.2.8 will be live in 20 minutes. Changelog:

    • Added "Use Death Timer" setting to Killable's Death & Despawn Triggers section. You can add a timer where after X seconds it will either despawn or die (you choose).
    • Fixed compilation error on Unity 3.5.7.
    • Added Custom Events feature, which Triggered Spawners can now use. You can make them distance-based, so that all Triggered Spawners within a certain distance will spawn a wave they specify for that event. Can also spawn the wave items looking at the event origin point. This can make enemies attack a player when a custom event happens. Very powerful!
    • Playmaker custom actions for Triggered Spawners have been updated for Custom Events, please reinstall the custom actions from the new version or you will not be able to compile.
    • Behavior Designer tasks for Triggered Spawners have been updated for Custom Events, please reinstall the custom actions from the new version or you will not be able to compile.
    • Added new Example Scene 5 for Custom Events.
    • Added CustomEventReceived method to Triggered Spawner Listener & Playmaker Listener for Triggered Spawner.
    • Moved Use Music Settings and Syncro Spawners Off buttons inside "Use Global Waves" section in Level Settings.
    • Added CoreGameKitFireCustomEvent Playmaker Custom Action.
    Some definite cool new stuff now with Custom Events!
     
  42. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Awesome! Its working for Unity 3.5.7 again! Thank you! :)

    I think UT should give you an award for being the BEST Asset Store Seller Support. Seriously!
     
  43. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Thanks so much! I got it to work with the help of some programmer friends, but your solution is near identical.
    Now I'm trying to set up a charge shot, Megaman style. I set up a world variable for the bullet Attack Points, but I don't know how to access it through code, in my shooting and charging script. I also suspect that there's a problem with this, because it'll change the Attack Points for all the active bullets. How do I only affect individual bullet attack points?

    Here's what I have so far
    Code (CSharp):
    1.     public float chargeRate = 1;
    2.     bool charging = false;
    3.     private TriggeredSpawner spawner;
    4.  
    5.     void Awake ()
    6.     {
    7.         //Talking to CoreGameKit TriggeredSpawner Script
    8.         spawner = this.GetComponent<TriggeredSpawner>();
    9.     }
    10.  
    11.    
    12. voidUpdate ()
    13.  {
    14. //Shootingandcharging
    15. if(Input.GetButtonDown ("Attack"))
    16.  {
    17. Debug.Log ("can charge");
    18. charging = true;
    19.  }
    20. if(charging == true)
    21.  {
    22. Debug.Log ("charging");
    23. //ArrowAttackPower = (ArrowAttackPower + (chargeRate * Time.deltaTime));
    24.  }
    25. if(Input.GetButtonUp ("Attack"))
    26.  {
    27. Debug.Log ("Shooting Button Down");
    28. charging = false;
    29. //ArrowAttackPower = 0;
    30. spawner.ActivateCodeTriggeredEvent1();
    31.  }
    32.  }
    33.  
     
    Last edited: Sep 8, 2014
  44. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Death Timer! awesome, thank you! i was about to start coding my own.
     
  45. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I wish there was such a category :) Do you want to email Caitlyn and ask about adding it to the Unity awards? Seriously :) Thank you.
     
  46. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No problem, it was fairly easy :)
     
  47. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Correct, changing a World Variable would affect all visible bullets, not just the one you're about to shoot. So don't use that. I would just spawn a different prefab from the charged one. A different prefab that has more attack points. You could use Code-Triggered Event 2. But then you'd be all out of code-triggered events to use. Maybe it would be cooler to use the brand new Custom Events?

    1) Upgrade to the latest version
    2) Go create the custom event at the bottom of LevelSettings prefab Inspector. Call it "PlayerChargeShot".
    3) In your script above, if charged do this code:

    LevelSettings.FireCustomEvent("PlayerChargeShot");

    4) Activate "CustomEvent" in your Triggered Spawner for the player. Select "PlayerChargeShot" and use your new more powerful charge shot prefab.

    That should do it! Oh and make sure to only fire Code-Triggered Event 1 if not charged. Although you could convert that to a 2nd custom event as well if you like.

    Truth be told, Code-Triggered events were just a temporary and less flexible way to get by without custom events until I found time to make them. Now that custom events exist I don't think there's a reason to use Code-Triggered Events instead. But I'll keep them around anyway for awhile. Eventually they will be going away.
     
  48. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Thanks so much for the help! Now my only worry about updating is that I'll lose a lot of what I've already set up in my game, up to now, using CGK. It's been a little while since I used plug-ins is Unity, so basically I'm asking if that's even something to worry about? If not I'll go ahead and get the update, otherwise I'll use the CodeTriggered2 Event.

    P.S.
    What should I watch out for if I use up both Code-Triggered Events?
     
    Last edited: Sep 9, 2014
  49. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Just make sure that your LevelSettings prefab is not linked to the one in the Core GameKit folder. If it is, you'll lose all your settings on LevelSettings.

    To check it, press that "select" button up top in its Inspector (the row of buttons is select, apply and revert). If it selects the prefab in the Core GameKit folder, you'll need to make your own prefab by dragging it into the Project view somewhere else outside of the Core GameKit folder. Or if those buttons aren't there, you're also safe, but I would create a prefab before upgrading.

    There's nothing to watch out for using both Code-Triggered events, except that you won't have any left when you want to do a 3rd thing. So I suggest upgrading and using Custom Events.
     
  50. Chibwemwn

    Chibwemwn

    Joined:
    Feb 6, 2013
    Posts:
    129
    Okay, so I have it working! Thanks so much. The next issue I have is that since I'm working on a local multiplayer game, I have to make sure that the ammo spawned, knows who spawned it, and what direction they should go based on the direction the spawner is facing. How can I make sure this works well, using CGK? I don't know how to access the most recently spawned bullet, from the player controller script.

    The goal is to have up to 4 players all spawning ammo and shooting in the direction they are individually facing.

    Here's what I have so far
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, yMin, yMax;
    8. }
    9.  
    10.  
    11. public class playerMovementBasic : MonoBehaviour {
    12.  
    13.  
    14.     public Vector2 maxSpeed = new Vector2 (20, 20);
    15.     public float dashSpeed = 0.0f;
    16.     public int dashCoolMax = 20;
    17.     public int dashCoolDown = 0;
    18.     public float startingDashSpeed = 300;
    19.     public float dashAccelleration = 2.0f;
    20.     public float accellerationTime = 7.0f;
    21.     public float chargeRate = 1.0f;
    22.     public float ArrowAttackPower = 0.0f;
    23.  
    24.  
    25.     public int playerID = 1;
    26.  
    27.  
    28.     public Boundary boundary;
    29.  
    30.     public bool facingRight = true;
    31.  
    32.     bool dashing = false;
    33.     bool charging = false;
    34.  
    35.     private Vector2 movement;
    36.  
    37.     private TriggeredSpawner spawner;
    38.    
    39.     void Awake ()
    40.     {
    41.         //Talking to CoreGameKit TriggeredSpawner Script
    42.         spawner = this.GetComponent<TriggeredSpawner>();
    43.     }
    44.  
    45.     void Update ()
    46.     {
    47.         //Shooting and charging
    48.         if(Input.GetButtonDown ("Player"+ playerID +"Attack"))
    49.         {
    50.             Debug.Log ("can charge");
    51.             charging = true;
    52.         }
    53.         if(charging == true)
    54.         {
    55.             Debug.Log ("charging");
    56.             ArrowAttackPower = (ArrowAttackPower + (chargeRate * Time.deltaTime ));
    57.  
    58.         }
    59.         if(Input.GetButtonUp ("Player"+ playerID +"Attack"))
    60.         {
    61.             Debug.Log ("Shooting Button Up");
    62.             charging = false;
    63.  
    64.             if(ArrowAttackPower < 3)
    65.             {
    66.                 spawner.ActivateCodeTriggeredEvent1();
    67.                 ArrowAttackPower = 0;
    68.             }
    69.             else
    70.             {
    71.                 spawner.ActivateCodeTriggeredEvent2();
    72.                 ArrowAttackPower = 0;
    73.             }
    74.            
    75.         }
    76.     }
    77.  
    78.     void FixedUpdate ()
    79.     {
    80.  
    81.  
    82.         //Move player
    83.         float move = Input.GetAxis ("Player"+ playerID +"Horizontal");
    84.         float moveVert = Input.GetAxis ("Player"+ playerID +"Vertical");
    85.            
    86.             //Dashing
    87.         if(Input.GetButtonDown ("Player"+ playerID +"Dash") && dashing == false)
    88.             {
    89.                
    90.                 //Debug.Log ("Step 1 Complete");
    91.                 dashing = true;
    92.                 dashSpeed = startingDashSpeed;
    93.             }
    94.            
    95.             //Accellerating
    96.             if(dashSpeed > 0f && dashCoolDown < 7)
    97.             {
    98.                 //Debug.Log ("Step 2 Complete");
    99.                 dashSpeed +=dashAccelleration;
    100.             }
    101.                 if(dashCoolDown > 0 && dashing == true)
    102.             {
    103.                 //Debug.Log ("Step 3 Complete");
    104.                 dashCoolDown --;
    105.             }
    106.             else if(dashCoolDown <= 0)
    107.             {
    108.                 //Debug.Log ("Step 4 Complete");
    109.                 dashing = false;
    110.                 dashCoolDown = dashCoolMax;
    111.                 dashSpeed = 0;
    112.             }
    113.            
    114.  
    115.             movement = new Vector2 (
    116.                 (maxSpeed.x + dashSpeed) * move,
    117.                 (maxSpeed.y + dashSpeed) * moveVert
    118.                 );
    119.  
    120.  
    121.             rigidbody2D.velocity = movement; //Move Character
    122.            
    123.  
    124.             rigidbody2D.position = new Vector2 //Keep player inbound
    125.                 (
    126.                     Mathf.Clamp (rigidbody2D.position.x, boundary.xMin, boundary.xMax),
    127.                     Mathf.Clamp (rigidbody2D.position.y, boundary.yMin, boundary.yMax)
    128.                 );
    129.  
    130.         if(!charging)
    131.         {
    132.             //Flip Character Sprite
    133.             if(move>0 && !facingRight)
    134.             {
    135.                 Flip ();
    136.             }
    137.             else if (move < 0 && facingRight)
    138.             {
    139.                 Flip ();
    140.             }
    141.         }
    142.  
    143.     }
    144.    
    145.  
    146.     void Flip()
    147.     {
    148.         facingRight = !facingRight;
    149.         Vector3 theScale = transform.localScale;
    150.         theScale.x *= -1;
    151.         transform.localScale = theScale;
    152.     }
    153.  
    154. }
    155.