2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

5 years ago
  1. using Unity.FPS.Game;
  2. using UnityEngine;
  3. namespace Unity.FPS.Gameplay
  4. {
  5. public class WeaponPickup : Pickup
  6. {
  7. [Tooltip("The prefab for the weapon that will be added to the player on pickup")]
  8. public WeaponController WeaponPrefab;
  9. protected override void Start()
  10. {
  11. base.Start();
  12. // Set all children layers to default (to prefent seeing weapons through meshes)
  13. foreach (Transform t in GetComponentsInChildren<Transform>())
  14. {
  15. if (t != transform)
  16. t.gameObject.layer = 0;
  17. }
  18. }
  19. protected override void OnPicked(PlayerCharacterController byPlayer)
  20. {
  21. PlayerWeaponsManager playerWeaponsManager = byPlayer.GetComponent<PlayerWeaponsManager>();
  22. if (playerWeaponsManager)
  23. {
  24. if (playerWeaponsManager.AddWeapon(WeaponPrefab))
  25. {
  26. // Handle auto-switching to weapon if no weapons currently
  27. if (playerWeaponsManager.GetActiveWeapon() == null)
  28. {
  29. playerWeaponsManager.SwitchWeapon(true);
  30. }
  31. PlayPickupFeedback();
  32. Destroy(gameObject);
  33. }
  34. }
  35. }
  36. }
  37. }