-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeaponPistol.cs
70 lines (55 loc) · 2.08 KB
/
WeaponPistol.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
using Godot;
using System;
public class WeaponPistol : WeaponPoint
{
private const float damage = 15;
private PackedScene bulletScene = ResourceLoader.Load("Bullet_Scene.tscn") as PackedScene;
public AnimationPlayer animationPlayer;
public override void _Ready() {
animationPlayer = GetNode<Player>("../../../").GetAnimationPlayer();
if (animationPlayer is AnimationPlayer) {
GD.Print("animation player not null in equip weapon");
} else {
if (animationPlayer != null) {
GD.Print("animation player is not instance in equip weapon: " + animationPlayer.GetType());
} else {
GD.Print("animation player is null in equip");
}
}
}
public override void FireWeapon() {
var clone = bulletScene.Instance() as Bullet;
var sceneRoot = GetTree().Root.GetChildren()[0] as Spatial;
sceneRoot.AddChild(clone);
clone.GlobalTransform = this.GlobalTransform;
clone.Scale = new Vector3(4, 4, 4);
clone.bulletDamage = damage;
}
public override bool EquipWeapon() {
if (animationPlayer.CurrentAnimationState() == AnimationPlayer.pistolIdle) {
isEnabled = true;
return true;
}
if (animationPlayer.CurrentAnimationState() == AnimationPlayer.idleUnarmed) {
animationPlayer.SetAnimation(AnimationPlayer.pistolEquip);
}
return false;
}
public override bool UnequipWeapon() {
if (animationPlayer.CurrentAnimationState() == AnimationPlayer.pistolIdle) {
animationPlayer.SetAnimation(AnimationPlayer.pistolUnequip);
}
if (animationPlayer.CurrentAnimationState() == AnimationPlayer.idleUnarmed) {
isEnabled = false;
return true;
} else {
return false;
}
}
}
public abstract class WeaponPoint : Spatial {
public bool isEnabled = false;
public abstract bool UnequipWeapon();
public abstract bool EquipWeapon();
public abstract void FireWeapon();
}