コード例 #1
0
ファイル: WeaponRifle.cs プロジェクト: fikma/FPS-Starter
    public override void FireWeapon()
    {
        var ray = GetNode <RayCast>("Ray_Cast");

        ray.ForceRaycastUpdate();

        if (ray.IsColliding())
        {
            var body = ray.GetCollider();
            if (body == PlayerNode)
            {
            }
            else if (body.HasMethod("BulletHit"))
            {
                if (body is RigidBodyHitTest)
                {
                    var aBody = body as RigidBodyHitTest;
                    aBody.BulletHit(DAMAGE, ray.GlobalTransform);
                }
                else if (body is Target)
                {
                    var aBody = body as Target;
                    aBody.BulletHit(DAMAGE, ray.GlobalTransform);
                }
                else if (body is TurretBodies turret)
                {
                    turret.BulletHit(DAMAGE, GlobalTransform.origin);
                }
            }
        }

        AmmoInWeapon -= 1;
        PlayerNode.CreateSound("Rifle_shot", ray.GlobalTransform.origin);
    }
コード例 #2
0
ファイル: WeaponPistol.cs プロジェクト: fikma/FPS-Starter
    public override void FireWeapon()
    {
        var     clone     = _bulletScene.Instance() as BulletScript;
        Spatial sceneRoot = GetTree().Root.GetChildren()[0] as Spatial;

        sceneRoot.AddChild(clone);

        clone.GlobalTransform = this.GlobalTransform;
        clone.Scale           = new Vector3(4, 4, 4);
        clone.BULLET_DAMAGE   = DAMAGE;

        AmmoInWeapon -= 1;

        PlayerNode.CreateSound("Pistol_shot", this.GlobalTransform.origin);
    }