Hi I’m using c# and I’m currently making a perk script and when the player picks up this perk the players ammo increases every 10 seconds. The perk is a game object as well.However my code doesn’t seem to be right as when I play through the game and error comes up saying
Here is the script I have used;
public class PerkScript : MonoBehaviour {
public GameObject ammoPerk;
float ammoUpTime = 10f;
// Use this for initialization
void Start () {
InvokeRepeating("TopUpAmmo", ammoUpTime, ammoUpTime);
}
// Update is called once per frame
void Update () {
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
PlayerScript playerScript = GetComponent<PlayerScript>();
if (hit.gameObject.tag == "AmmoPerk")
{
playerScript.reserveAmmo += 10;
Destroy(hit.gameObject);
}
}
}
Thanks for the help if any and would be much appreciated.