-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
1430 lines (1272 loc) · 41.9 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public enum Direction { Left, Right };
public class Player : MonoBehaviour
{
//[HideInInspector]
public float hor; // Get the Horizontal Input.
[HideInInspector]
public bool facingRight; // For determining which way the player is currently facing.
[HideInInspector]
public bool grounded = true; // Whether or not the player is grounded.
[HideInInspector]
public bool walking = false; // Determines if the player is walking.
[HideInInspector]
public bool stuckToWall = false; // Used to stop the player from moving when stuck to a wall.
[HideInInspector]
public bool falling = false;
[HideInInspector]
public bool dashing = false; // Determines if the player is dashing.
[HideInInspector]
public bool crouching = false; // Determines if the player is crouching.
[HideInInspector]
public bool sliding = false; // Determines if the player is sliding.
//[HideInInspector]
public bool onLadder = false; // Determines if the player is on a ladder.
[HideInInspector]
public GameObject frontCheckTop; // A position marking to check if the player's front.
[HideInInspector]
public GameObject frontCheckBot; // A position marking to check if the player's front.
[HideInInspector]
public Transform groundCheck; // A position marking to check if the player is grounded.
[HideInInspector]
public Collider2D groundCollider; // Ground collider object.
[HideInInspector]
public bool jumpDown = false; // Determines if the player is about to jump down.
[HideInInspector]
public bool jumping = false; // Determines if the player is jumping.
[HideInInspector]
public bool jumpingThrough = false; // Determines if the player is jumping through a platform.
[HideInInspector]
public bool Bazooka = false;
private AudioClip Launch;
private GameObject rocketKick;
private GameObject bulletPrefab;
private Transform bulletSpawnTransform;
[HideInInspector]
public bool Shotgun = false;
private AudioClip shotgunShot;
public bool fire = false;
private GameObject shotgunKick;
private GameObject shotgunBullet;
private Transform shotgunBulletSpawn;
[HideInInspector]
public bool Staff = false;
private AudioClip staffShot;
private AudioClip staffBoom;
private GameObject staffBullet;
private Transform staffBulletSpawn;
[HideInInspector]
public bool Granade = false;
private AudioClip granadeShot;
private GameObject granadeBullet;
private Transform granadeBulletSpawn;
[HideInInspector]
public bool Watergun = false;
private AudioClip watergunShot;
private GameObject watergunKick;
private GameObject watergunBullet;
private Transform watergunBulletSpawn;
[HideInInspector]
public bool Machinegun = false;
private AudioClip machinegunShot;
private GameObject machinegunKick;
private GameObject machinegunBullet;
private Transform machinegunBulletSpawn;
[HideInInspector]
public bool Boomerang = false;
private AudioClip boomerangShot;
private GameObject boomerangBullet;
private Transform boomerangBulletSpawn;
private float timer;
[HideInInspector]
public bool stop = false;
private static Player instance = null;
public static Player Instance {
get { return instance; }
}
[Tooltip("Select the direction in which the sprites are facing.")]
public Direction spriteDirection;
[Tooltip("Select the layer that should be used for platforms.")]
public LayerMask platformLayer;
[Tooltip("Select the layer that should be used for the ground.")]
public LayerMask groundLayer;
[Tooltip("Set the radius for the ground check. This creates a circle at the feet of the player, checking if anything from the ground or platform layer collides with the circle.")]
public float groundRadius = 0.12f;
[Tooltip("Enable or disable player rotation when on a rotated platform (slope).")]
public bool rotateOnSlope = true;
[Tooltip("Enable or disable player movement after death.")]
public bool moveAfterDeath = true;
[Tooltip("You can enable this to keep the player's velocity when hitting the ground. This is experimental and currently defaults to false.")]
public bool keepVelocityOnGround = false;
[Tooltip("The timer used for the remembering the player's velocity when hitting the ground. Don't give this a high value.")]
public float groundedVelocityTime = 0.05f;
public bool timedFire = false;
private PlayerJump playerJump;
private PlayerWall playerWall;
private PlayerRun playerRun;
private PlayerCrouch playerCrouch;
private PlayerDash playerDash;
private PlayerPlatform playerPlatform;
private Quaternion normalRotation;
[HideInInspector]
public Animator animator;
private bool flipAgain = false;
private float gravityScale = 2f;
private bool isDead = false;
private float groundedXVelocity;
private float groundedTimer;
private bool wallSliding = false;
private bool wallRunning = false;
private bool wallJumping = false;
private BoxCollider2D boxCollider;
private CircleCollider2D circleCollider;
[HideInInspector]
public float attackTimer;
private Pickup pickup;
public float nextFire;
private float machinegunFireRate = 0.25f;
public bool boomerangThrowable = true;
[HideInInspector]
public GameObject cameraFind;
[HideInInspector]
public CameraFollowFinal cam;
[HideInInspector]
public GameObject orient;
[HideInInspector]
public GameObject came;
private GameObject power;
private GameObject boom;
public GameObject boomOrient;
public float staffTimer;
public int staffClicks;
public bool staffFired = false;
private GameObject boomSpawn;
[HideInInspector]
public bool shp = false;
public GameObject ss;
private AudioClip sG;
private AudioClip wG;
public GameObject goodSpawn;
public bool moveIt = false;
private AudioClip outOfAmmo;
public bool isAttacking;
[HideInInspector]
public GameObject fightButton;
private bool punk;
private bool dino;
private bool ship;
private bool mach;
private bool king;
private Image tape;
private Text round;
private Text waveText;
private Text scoreText;
private Text scorePoints;
private Text moneyText;
private Text moneyPoints;
private bool fightClicked;
private Camera minimapCamera;
private KGFMapSystem minimap;
[HideInInspector]
public bool fell;
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
void Start ()
{
boxCollider = GetComponent<BoxCollider2D>();
circleCollider = GetComponent<CircleCollider2D>();
goodSpawn = GameObject.Find ("EndSpawnBack");
groundCheck = transform.Find("groundCheck");
frontCheckTop = new GameObject("frontCheckTop");
frontCheckBot = new GameObject("frontCheckBot");
playerJump = GetComponent<PlayerJump>();
playerWall = GetComponent<PlayerWall>();
playerRun = GetComponent<PlayerRun>();
playerCrouch = GetComponent<PlayerCrouch>();
playerDash = GetComponent<PlayerDash>();
playerPlatform = GetComponent<PlayerPlatform>();
normalRotation = transform.localRotation;
animator = GetComponent<Animator>();
pickup = GetComponent<Pickup>();
cam = GetComponentInChildren<CameraFollowFinal> ();
came = GameObject.FindWithTag ("MainCamera");
frontCheckTop.transform.parent = transform;
frontCheckBot.transform.parent = transform;
sG = (Resources.Load ("Weapons/Sounds/ReloadShotgun")) as AudioClip;
wG = (Resources.Load ("Weapons/Sounds/ReloadWatergun")) as AudioClip;
bulletPrefab = (Resources.Load("Weapons/Rocket/Player Bullet"))as GameObject;
rocketKick = (Resources.Load("Weapons/WeaponKicks/RocketKick"))as GameObject;
shotgunBullet = (Resources.Load("Weapons/Shotgun/ShotgunSpraySystem"))as GameObject;
shotgunKick = (Resources.Load("Weapons/WeaponKicks/ShotgunKick"))as GameObject;
staffBullet = (Resources.Load("Weapons/Staff/Fireball"))as GameObject;
granadeBullet = (Resources.Load("Weapons/Granade/Granade2"))as GameObject;
watergunBullet = (Resources.Load("Weapons/Watergun/WaterGunBullet"))as GameObject;
watergunKick = (Resources.Load("Weapons/WeaponKicks/WatergunKick"))as GameObject;
machinegunBullet = (Resources.Load("Weapons/Machinegun/MachineGunBullet"))as GameObject;
machinegunKick = (Resources.Load("Weapons/WeaponKicks/MachinegunKick"))as GameObject;
boomerangBullet = (Resources.Load("Weapons/Boomerang/Boomerang2"))as GameObject;
power = (Resources.Load("Weapons/Staff/Power"))as GameObject;
boom = (Resources.Load("Weapons/Staff/Boom"))as GameObject;
Launch = (Resources.Load ("Weapons/Sounds/DoodleRocketLaunch"))as AudioClip;
shotgunShot = (Resources.Load ("Weapons/Sounds/DoodleShotgunShot"))as AudioClip;
staffShot = (Resources.Load ("Weapons/Sounds/DoodleStaffShot"))as AudioClip;
staffBoom = (Resources.Load ("Weapons/Sounds/DoodleStaffSlam"))as AudioClip;
granadeShot = (Resources.Load ("Weapons/Sounds/DoodleGranadeThrow"))as AudioClip;
watergunShot = (Resources.Load ("Weapons/Sounds/DoodleWatergun"))as AudioClip;
machinegunShot = (Resources.Load ("Weapons/Sounds/DoodleMachinegunFire"))as AudioClip;
boomerangShot = (Resources.Load ("Weapons/Sounds/DoodleGranadeThrow"))as AudioClip;
outOfAmmo = (Resources.Load ("Weapons/Sounds/Click"))as AudioClip;
fightButton = GameObject.Find("Fight");
fightButton.SetActive(false);
//transform.position = ss.transform.position;
if (spriteDirection == Direction.Right)
{
facingRight = true;
}
else
{
facingRight = false;
Flip();
}
}
public void FightClicked()
{
GameObject.Find("CF-Complete-Physics-Platformer").GetComponent<TouchController>().b = true;
GameObject.Find("CF-Complete-Physics-Platformer").GetComponent<TouchController>().a = true;
tape = GameObject.Find("Tape1").GetComponent<Image>();
tape.enabled = false;
round = GameObject.Find("Round").GetComponent<Text>();
round.enabled = false;
waveText = GameObject.Find("WaveText").GetComponent<Text>();
waveText.enabled = false;
scoreText = GameObject.Find("ScoreText").GetComponent<Text>();
scoreText.enabled = false;
scorePoints = GameObject.Find("ScorePoints").GetComponent<Text>();
scorePoints.enabled = false;
moneyText = GameObject.Find("MoneyText").GetComponent<Text>();
moneyText.enabled = false;
moneyPoints = GameObject.Find("MoneyPoints").GetComponent<Text>();
moneyPoints.enabled = false;
minimapCamera = GameObject.Find("camera_minimap").GetComponent<Camera>();
minimapCamera.enabled = false;
minimap = GameObject.Find("KGFMapSystem").GetComponent<KGFMapSystem>();
minimap.itsDataModuleMinimap.itsGlobalSettings.itsHideGUI = true;
fightClicked = true;
fightButton.SetActive(false);
if (king)
{
stop = true;
Stop();
moveIt = true;
animator.SetTrigger("FinalBattle");
animator.SetBool("finalBattle", true);
king = false;
}
if (punk)
{
stop = true;
Stop();
moveIt = true;
animator.SetTrigger("PunkBossSpawn");
animator.SetBool("punkBossSpawn", true);
punk = false;
}
if (dino)
{
stop = true;
Stop();
moveIt = true;
animator.SetTrigger("DinoBossSpawn");
animator.SetBool("dinoBossSpawn", true);
dino = false;
}
if (mach)
{
stop = true;
Stop();
moveIt = true;
animator.SetTrigger("MachineBossSpawn");
animator.SetBool("machineBossSpawn", true);
mach = false;
}
if (ship)
{
stop = true;
Stop();
moveIt = true;
shp = true;
animator.SetTrigger("AlienBossSpawn");
animator.SetBool("alienBossSpawn", true);
ship = false;
}
}
public void OnTriggerEnter2D (Collider2D col)
{
if (col.gameObject.tag == "Start")
{
if(!fightClicked)
{
fightButton.SetActive(true);
}
king = true;
}
else if (col.gameObject.tag == "DinoStart")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
dino = true;
}
else if (col.gameObject.tag == "MachineBossSpawn")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
mach = true;
}
else if (col.gameObject.tag == "BossSoldierSpawn")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
punk = true;
}
else if (col.gameObject.tag == "AlianSpawn")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
ship = true;
}
if (col.gameObject.tag == "DinoBack")
{
col.gameObject.GetComponent<DinoBack>().DinoBack1();
fightClicked = false;
dino = false;
}
if (col.gameObject.tag == "MachineBack")
{
col.gameObject.GetComponent<MachineBack>().MachineBack1();
fightClicked = false;
mach = false;
}
if (col.gameObject.tag == "ShipBack")
{
shp = false;
col.gameObject.GetComponent<SpaceshipBack>().ShipBack1();
fightClicked = false;
ship = false;
}
if (col.gameObject.tag == "PunkBack")
{
col.gameObject.GetComponent<PunkBack>().PunkBack1();
fightClicked = false;
punk = false;
}
else if (col.gameObject.name == "SpringObject")
{
col.gameObject.GetComponent<Spring>().GO ();
}
else if (col.gameObject.CompareTag("End"))
{
transform.position = goodSpawn.transform.position;
}
}
public void OnTriggerStay2D(Collider2D col)
{
if (col.gameObject.tag == "Start")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
king = true;
}
else if (col.gameObject.tag == "DinoStart")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
dino = true;
}
else if (col.gameObject.tag == "MachineBossSpawn")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
mach = true;
}
else if (col.gameObject.tag == "BossSoldierSpawn")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
punk = true;
}
else if (col.gameObject.tag == "AlianSpawn")
{
if (!fightClicked)
{
fightButton.SetActive(true);
}
ship = true;
}
}
public void OnTriggerExit2D(Collider2D col)
{
if (col.gameObject.tag == "Start")
{
fightButton.SetActive(false);
king = false;
}
else if (col.gameObject.tag == "DinoStart")
{
fightButton.SetActive(false);
dino = false;
}
else if (col.gameObject.tag == "MachineBossSpawn")
{
fightButton.SetActive(false);
mach = false;
}
else if (col.gameObject.tag == "BossSoldierSpawn")
{
fightButton.SetActive(false);
punk = false;
}
else if (col.gameObject.tag == "AlianSpawn")
{
fightButton.SetActive(false);
ship = false;
}
}
public void stop1()
{
staffFired = false;
isAttacking = false;
animator.SetBool ("StaffFire", false);
fire = false;
}
public void areaAttack()
{
boomOrient = GameObject.Find ("BoomSpawnPoint");
GameObject newBoom = Instantiate (boom) as GameObject;
newBoom.transform.position = new Vector3 (boomOrient.transform.position.x, boomOrient.transform.position.y);
GetComponent<AudioSource>().PlayOneShot(staffBoom,1.0f);
}
public void areaAttackStop()
{
stop = false;
Stop();
animator.SetBool ("StaffBoom", false);
isAttacking = false;
Destroy (GameObject.Find ("Power(Clone)"));
fire = false;
}
void FixedUpdate()
{
if (stuckToWall || onLadder)
{
GetComponent<Rigidbody2D>().gravityScale = 0;
}
else if (shp)
{
GetComponent<Rigidbody2D>().gravityScale = 0.5f;
}
else
{
GetComponent<Rigidbody2D>().gravityScale = gravityScale;
}
if (keepVelocityOnGround && groundedXVelocity > 0)
{
SetXVelocity(groundedXVelocity);
}
}
void Update()
{
animator.SetBool("grounded", grounded);
animator.SetBool("walking", walking);
animator.SetBool("crouching", crouching);
animator.SetBool("sliding", sliding);
animator.SetBool("dashing", dashing);
animator.SetBool("falling", falling);
animator.SetBool("wall", stuckToWall);
animator.SetBool("onLadder", onLadder);
animator.SetBool("jumpingThrough", jumpingThrough);
if (timer > 0f)
{
timer -= Time.deltaTime;
}
if (timer < 0f)
{
timer = 0f;
}
if (timer == 0f)
{
WSVibrator.Cancel();
}
if (orient == null)
{
orient = GameObject.Find("KingOrient");
}
if (goodSpawn == null)
{
goodSpawn = GameObject.Find ("EndSpawnBack");
}
if (attackTimer > 0f)
{
attackTimer -= Time.deltaTime;
}
if (attackTimer == 0f && timedFire)
{
timedFire = false;
fire = false;
}
if (nextFire > 0f)
{
nextFire -= Time.deltaTime;
}
if (attackTimer < 0f)
{
attackTimer = 0f;
}
if (staffTimer < 0f)
{
staffTimer = 0f;
}
if (staffTimer > 0f)
{
staffTimer -= Time.smoothDeltaTime;
}
if (staffTimer == 0)
{
staffClicks = 0;
}
if (nextFire < 0f)
{
nextFire = 0f;
}
Vector2 pos = transform.position;
if (facingRight)
{
frontCheckTop.transform.position = new Vector2 (pos.x + boxCollider.offset.x + (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));
frontCheckBot.transform.position = new Vector2 (pos.x + boxCollider.offset.x + (boxCollider.size.x / 2) + 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius/2));
}
else
{
frontCheckTop.transform.position = new Vector2 (pos.x + boxCollider.offset.x - (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));
frontCheckBot.transform.position = new Vector2 (pos.x + boxCollider.offset.x - (boxCollider.size.x / 2) - 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius/2));
}
if (!stop)
{
hor = CFInput.GetAxis ("Horizontal");
animator.SetFloat("horizontal", Mathf.Abs(hor));
}
animator.SetFloat("xSpeed", Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x));
animator.SetFloat("ySpeed", GetComponent<Rigidbody2D>().velocity.y);
if (!OnPlatform())
{
groundCollider = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer);
}
if (keepVelocityOnGround && groundedXVelocity > 0)
{
if (groundedTimer > 0)
{
groundedTimer -= Time.deltaTime;
}
else
{
groundedXVelocity = 0;
}
}
if (groundCollider && !jumpingThrough)
{
if (keepVelocityOnGround && !grounded)
{
groundedXVelocity = GetComponent<Rigidbody2D>().velocity.x;
groundedTimer = groundedVelocityTime;
}
grounded = true;
jumping = false;
if (rotateOnSlope && !OnPlatform()) { transform.rotation = groundCollider.transform.localRotation; }
if (falling)
{
animator.SetTrigger("stateComplete");
}
falling = false;
}
else
{
transform.rotation = normalRotation;
grounded = false;
}
if((hor > 0 && !facingRight) || (hor < 0 && facingRight) || flipAgain)
{
Flip();
}
if (Staff)
{
if (pickup.staffAmmo > 0f && staffClicks == 1 && !staffFired)
{
if (staffTimer < 0.3f)
{
Vib100();
isAttacking = true;
fire = true;
animator.SetBool("StaffFire", true);
GetComponent<AudioSource>().PlayOneShot(staffShot, 1.0f);
GameObject newBullet = Instantiate(staffBullet);
StaffController bullCon = newBullet.GetComponent<StaffController>();
bullCon.playerObject = gameObject;
bullCon.StaffShoot();
newBullet.transform.position = staffBulletSpawn.position;
pickup.staffAmmo--;
staffFired = true;
}
}
}
if (CFInput.GetButtonDown("Fire1"))
{
Fire();
}
if(CFInput.GetButton("Fire1") && Machinegun)
{
machinegunBulletSpawn = GameObject.Find("MachineGunSpawnPoint").transform;
if (!onLadder && !stuckToWall)
{
if (nextFire == 0f && pickup.machinegunAmmo > 0f)
{
Vib50();
isAttacking = true;
nextFire = machinegunFireRate;
animator.SetBool("MachineGunFire", true);
GetComponent<AudioSource>().PlayOneShot(machinegunShot, 1.0f);
GameObject newBullet = Instantiate(machinegunBullet);
GameObject newKick = Instantiate(machinegunKick);
MachineGunController bullCon = newBullet.GetComponent<MachineGunController>();
ParticleFlip kickCon = newKick.GetComponent<ParticleFlip>();
bullCon.playerObject = gameObject;
kickCon.playerObject = gameObject;
bullCon.MachineGunShoot();
kickCon.MachineGunShoot();
newBullet.transform.position = machinegunBulletSpawn.position;
newKick.transform.position = machinegunBulletSpawn.position;
pickup.machinegunAmmo--;
}
else if (pickup.machinegunAmmo == 0f)
{
isAttacking = false;
animator.SetBool("MachineGunFire", false);
GetComponent<AudioSource>().PlayOneShot(outOfAmmo);
}
}
}
if (CFInput.GetButtonUp("Fire1") && Machinegun)
{
isAttacking = false;
animator.SetBool("MachineGunFire", false);
}
}
public void Fire()
{
if (!stop)
{
if (Bazooka == true)
{
bulletSpawnTransform = GameObject.Find("PLSpawn").transform;
if (!fire && !timedFire && !onLadder && !stuckToWall)
{
if (pickup.bazookaAmmo > 0f)
{
Vib100();
isAttacking = true;
fire = true;
animator.SetBool("BazookaFire", true);
GetComponent<AudioSource>().PlayOneShot(Launch, 1.0f);
GameObject newBullet = (GameObject)Instantiate(bulletPrefab);
GameObject newKick = (GameObject)Instantiate(rocketKick);
PlayerBulletController bullCon = newBullet.GetComponent<PlayerBulletController>();
ParticleFlip kickCon = newKick.GetComponent<ParticleFlip>();
bullCon.playerObject = gameObject;
kickCon.playerObject = gameObject;
bullCon.launchBullet();
kickCon.launchBullet();
newBullet.transform.position = bulletSpawnTransform.position;
newKick.transform.position = bulletSpawnTransform.position;
pickup.bazookaAmmo--;
}
else if (pickup.bazookaAmmo == 0f)
{
GetComponent<AudioSource>().PlayOneShot(outOfAmmo);
}
}
}
if (Shotgun == true)
{
shotgunBulletSpawn = GameObject.Find("ShotGunSpawnPoint").transform;
if (!fire && !onLadder && !stuckToWall)
{
if (pickup.shotgunAmmo > 0f)
{
Vib100();
isAttacking = true;
fire = true;
animator.SetBool("ShotgunFire", true);
GetComponent<AudioSource>().PlayOneShot(shotgunShot, 1.0f);
GameObject newBullet = (GameObject)Instantiate(shotgunBullet);
GameObject newKick = (GameObject)Instantiate(shotgunKick);
ShotgunController bullCon = newBullet.GetComponent<ShotgunController>();
ParticleFlip kickCon = newKick.GetComponent<ParticleFlip>();
bullCon.playerObject = gameObject;
kickCon.playerObject = gameObject;
bullCon.ShotgunShoot();
kickCon.ShotgunShoot();
newBullet.transform.position = shotgunBulletSpawn.position;
newKick.transform.position = shotgunBulletSpawn.position;
pickup.shotgunAmmo--;
}
else if (pickup.shotgunAmmo == 0f)
{
GetComponent<AudioSource>().PlayOneShot(outOfAmmo);
}
}
}
if (Watergun == true)
{
watergunBulletSpawn = GameObject.Find("WaterGunSpawnPoint").transform;
if (!fire && !onLadder && !stuckToWall)
{
Vib100();
isAttacking = true;
fire = true;
animator.SetBool("WaterGunFire", true);
GetComponent<AudioSource>().PlayOneShot(watergunShot, 1.0f);
GameObject newBullet = (GameObject)Instantiate(watergunBullet);
GameObject newKick = (GameObject)Instantiate(watergunKick);
WaterGunController bullCon = newBullet.GetComponent<WaterGunController>();
ParticleFlip kickCon = newKick.GetComponent<ParticleFlip>();
bullCon.playerObject = gameObject;
kickCon.playerObject = gameObject;
bullCon.WaterGunShoot();
kickCon.WaterGunShoot();
newBullet.transform.position = watergunBulletSpawn.position;
newKick.transform.position = watergunBulletSpawn.position;
}
}
if (Staff)
{
staffBulletSpawn = GameObject.Find("StaffSpawnPoint").transform;
if (!fire && !onLadder && !stuckToWall)
{
staffClicks++;
if (staffClicks == 1)
{
staffTimer = 0.5f;
}
else if (pickup.staffAmmo > 5f && staffClicks == 2 && !staffFired)
{
if (staffTimer > 0.3f)
{
Vib500();
isAttacking = true;
fire = true;
stop = true;
Stop();
animator.SetBool("StaffBoom", true);
GameObject newPower = Instantiate(power);
newPower.transform.position = staffBulletSpawn.position;
pickup.staffAmmo -= 5;
}
}
else if (pickup.staffAmmo == 0f)
{
GetComponent<AudioSource>().PlayOneShot(outOfAmmo);
}
}
}
if (Granade == true)
{
granadeBulletSpawn = GameObject.Find("GranadeSpawnPoint").transform;
if (!fire && !timedFire && !onLadder && !stuckToWall)
{
if (pickup.granadeAmmo > 0f)
{
isAttacking = true;
fire = true;
animator.SetBool("GranadeFire", true);
}
else if (pickup.granadeAmmo == 0f)
{
GetComponent<AudioSource>().PlayOneShot(outOfAmmo);
}
}
}
if (Boomerang == true)
{
boomerangBulletSpawn = GameObject.Find("BoomerangSpawnPoint").transform;
if (!fire && !timedFire && !onLadder && !stuckToWall)
{
isAttacking = true;
fire = true;
animator.SetBool("BoomerangFire", true);
}
}
}
}
public void MachinegunStop()
{
isAttacking = false;
animator.SetBool ("MachineGunFire", false);
}
public void ShotgunStop()
{
isAttacking = false;
animator.SetBool ("ShotgunFire", false);
fire = false;
}
public void BazookaStop()
{
isAttacking = false;
animator.SetBool ("BazookaFire", false);
attackTimer = 0.7f;
timedFire = true;
}
public void BoomerangFire()
{
Vib100();
GetComponent<AudioSource>().PlayOneShot(boomerangShot);
GameObject newBullet = Instantiate (boomerangBullet);
newBullet.transform.position = boomerangBulletSpawn.position;
}
public void BoomerangStop()
{
isAttacking = false;
animator.SetBool ("BoomerangFire", false);
attackTimer = 0.5f;
timedFire = true;
}
public void ReloadShotgun()
{
GetComponent<AudioSource>().PlayOneShot (sG);
}
public void ReloadWatergun()
{
GetComponent<AudioSource>().PlayOneShot (wG);
}
public void GranadeFire()
{
Vib100();
GetComponent<AudioSource>().PlayOneShot(granadeShot,1.0f);
GameObject newBullet = (GameObject)Instantiate (granadeBullet);
GranadeController bullCon = newBullet.GetComponent<GranadeController> ();
bullCon.playerObject = gameObject;
bullCon.GranadeShoot ();
newBullet.transform.position = granadeBulletSpawn.position;
pickup.granadeAmmo --;
}
public void GranadeStop()
{
isAttacking = false;
animator.SetBool ("GranadeFire", false);
attackTimer = 0.2f;
timedFire = true;
}
public void WatergunStop()
{
isAttacking = false;
animator.SetBool ("WaterGunFire", false);
fire = false;
}
public void Dead()
{
isDead = true;
SetJumps(0);