Gun Reloads now if empty

This commit is contained in:
pbg2h23akl 2024-07-01 16:37:19 +02:00
parent 6bb0bc1c39
commit df37d14120
3 changed files with 32 additions and 61 deletions

View File

@ -238,3 +238,5 @@ MonoBehaviour:
m_EditorClassIdentifier:
spawnpoint: {fileID: 3929927056536112425}
bullet: {fileID: 939049122039926632, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
dataBullet: {fileID: 11400000, guid: cafd241bae342f446ae8141cc5d72daf, type: 2}
reloadTime: 3

View File

@ -789,63 +789,6 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 940378051}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &1030353343
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 939049122039926632, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_Name
value: Bullet
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalPosition.x
value: 5.431
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3286218375903244322, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5bd04146a95212e41bc2c52b7079e131, type: 3}
--- !u!1 &1062964497
GameObject:
m_ObjectHideFlags: 0
@ -1984,4 +1927,3 @@ SceneRoots:
- {fileID: 1513164528}
- {fileID: 1124830199}
- {fileID: 829478755}
- {fileID: 1030353343}

View File

@ -7,17 +7,44 @@ public class WeaponScript : MonoBehaviour
public GameObject spawnpoint;
public GameObject bullet;
private void shoot(){
public DataBullet dataBullet;
private int ammo;
private bool isReloading = false;
private float time = 0;
public float reloadTime;
public void reload(){
if(ammo == 0){
isReloading = true;
}
if(isReloading){
time += Time.deltaTime;
if(time > reloadTime){
ammo = dataBullet.ammo;
time = 0;
isReloading = false;
}
}
}
public void shoot(){
if(ammo != 0){
if(Input.GetKeyDown(KeyCode.Mouse0)){
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
ammo--;
}
}else{
reload();
}
}
void Start()
{
dataBullet = GetComponentInChildren<DataBullet>();
ammo = dataBullet.ammo;
}
// Update is called once per frame