-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeaponDeposit.cs
63 lines (47 loc) · 1.72 KB
/
WeaponDeposit.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
using System.Collections.Generic;
using UnityEngine;
public sealed class WeaponDeposit : MonoBehaviour
{
[SerializeField] private ItemManager itemManager;
[SerializeField] private List<GameObject> WeaponDepositLocations;
[SerializeField] private List<GameObject> DepositedWeapons;
[SerializeField] private int nextWeaponposition = 0;
private GameObject _currentWeapon;
private GameObject _depositedWeapon;
private void Start()
{
for (int i = 0; i < 3; i++) DepositedWeapons.Add(null);
}
public void GetFinalWeapon()
{
var finalWeapon = new GameObject();
foreach (var weaponPart in itemManager.GetItems())
{
weaponPart.transform.SetParent(finalWeapon.transform);
}
if(WeaponDepositLocations != null)
{
_currentWeapon = WeaponDepositLocations[nextWeaponposition];
}
SetNextPosition();
var _weapon = Instantiate(finalWeapon, _currentWeapon.transform.position, _currentWeapon.transform.rotation);
if(DepositedWeapons.Count == 3) Destroy(DepositedWeapons[nextWeaponposition]);
DepositedWeapons[nextWeaponposition] = _weapon;
_depositedWeapon = _weapon;
}
public void SetNextPosition()
{
nextWeaponposition++;
if (nextWeaponposition == 3) nextWeaponposition = 0;
}
public void ClearWeapon(int numb)
{
print(numb);
if(DepositedWeapons[numb].gameObject != null) Destroy(DepositedWeapons[numb]);
}
/// <summary>
/// Used to put the created weapons in the background?
/// </summary>
/// <returns>The last deposited weapon</returns>
public GameObject GetDepositedWeapon() => _depositedWeapon;
}