update
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Unity.FPS.Game;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.FPS.Gameplay
|
||||
{
|
||||
public class WeaponPickup : Pickup
|
||||
{
|
||||
[Tooltip("The prefab for the weapon that will be added to the player on pickup")]
|
||||
public WeaponController WeaponPrefab;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// Set all children layers to default (to prefent seeing weapons through meshes)
|
||||
foreach (Transform t in GetComponentsInChildren<Transform>())
|
||||
{
|
||||
if (t != transform)
|
||||
t.gameObject.layer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPicked(PlayerCharacterController byPlayer)
|
||||
{
|
||||
PlayerWeaponsManager playerWeaponsManager = byPlayer.GetComponent<PlayerWeaponsManager>();
|
||||
if (playerWeaponsManager)
|
||||
{
|
||||
if (playerWeaponsManager.AddWeapon(WeaponPrefab))
|
||||
{
|
||||
// Handle auto-switching to weapon if no weapons currently
|
||||
if (playerWeaponsManager.GetActiveWeapon() == null)
|
||||
{
|
||||
playerWeaponsManager.SwitchWeapon(true);
|
||||
}
|
||||
|
||||
PlayPickupFeedback();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user