-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectAmmo.cs
More file actions
51 lines (45 loc) · 1.1 KB
/
selectAmmo.cs
File metadata and controls
51 lines (45 loc) · 1.1 KB
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
using UnityEngine;
public class selectAmmo : MonoBehaviour
{
public int selectedAmmo = 0;
void Start()
{
ammoPick();
}
// Update is called once per frame
void Update()
{
int lastAmmo = selectedAmmo;
if(Input.GetAxis("Mouse ScrollWheel") > 0f){
if(selectedAmmo >= transform.childCount -1){
selectedAmmo = 0;
}
else{
selectedAmmo++;
}
}
if(Input.GetAxis("Mouse ScrollWheel") < 0f){
if(selectedAmmo <= 0){
selectedAmmo = transform.childCount - 1;
}
else{
selectedAmmo--;
}
}
if(lastAmmo != selectedAmmo){
ammoPick();
}
}
void ammoPick(){
int i = 0;
foreach(Transform ammo in transform){
if(i== selectedAmmo){
ammo.gameObject.SetActive(true);
}
else{
ammo.gameObject.SetActive(false);
}
i++;
}
}
}