After more research I have not found the solution, making a response PaxNemesis I thank btw who give a script here on the site reloading of ammo I took the idea for his script only if the player supports several times on the “R” key it gets ammunition at will, and if he picks up ammo and reload it loses all the ammunition that the pick …
What I seek is the ability to pick clips that give ammunition when the player input “R”
For example, I 5Clips 10Munition and I reload and I 4clips and 50Munitions
here is the script to publish PaxNemesis
So how to pick the clips that come in the script to add that when you press the R using the following?
Thank you for your reply but it does not work.
I’ll post my two Script.
Ammo Pickup and a piece of my shooting script with ammos
Script PickUp :
using UnityEngine;
using System.Collections;
public class Ammo : MonoBehaviour {
//script on player
private GameObject shootObject;
void Start () {
shootObject = GameObject.FindWithTag("shooter");
}
void OnTriggerEnter(Collider Cube){
if (Cube.tag == "ammo") {
shootObject.GetComponent<Input>().ammo += 50;
Destroy (Cube.gameObject);
}
}
}
Small parenthesis, This script works BUT If for example I open a Scene or Unity, software Script does not work
(Error: Object reference not set to instance of year year object)
And so when the script work adds me well Ammo 50 in the weapon the player.
Then the Script :
using UnityEngine;
using System.Collections.Generic;
public class Input: MonoBehaviour
public int ammo;
public bool reloading = false;
void Start () {
ammo = 50;
}
protected virtual void Update()
{
if (Input.GetKeyDown(KeyCode.R))
Reload();
UpdateCursorLock ();
if (Player.Pause.Get () == true)
return;
if (!m_AllowGameplayInput)
return;
InputAttack ();
}
protected virtual void UpdateCursorLock()
{
if (Input.GetAxis ("Fire1") > 0.5f || Input.GetMouseButton (0)) {
if (!reloading && ammo > 0) {
ammo --;
Player.Attack.TryStop ();
Fire ();
}
if (ammo <= 0)
Reload();
Screen.lockCursor = false;
Screen.lockCursor = true;
}
}
void Reload()
{
reloading = true;
ammo = 50;
reloading = false;
}
So now back to my question and you answer it-is that it will work with your script on my own?