So, I’m going a little off Rick’s setup for collecting resources, and I’ve run into a bit of a wall. What I’m going for is something more similar to Plants Vs. Zombies where the unit spawns a resource that you have to click to collect. I’ve pasted the code I have so far below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spore : MonoBehaviour
{
[SerializeField] GameObject collectParticles;
[SerializeField] AudioClip collectSFX;
[SerializeField] float collectSFXDuration = 5f;
public void OnMouseDown()
{
AddSpores();
TriggerCollectionVFX();
Destroy(gameObject);
}
private void TriggerCollectionVFX()
{
GameObject collectVFX = Instantiate(collectParticles, transform.position, transform.rotation);
Destroy(collectVFX, collectSFXDuration);
}
public void AddSpores(int amount)
{
FindObjectOfType<SporeDisplay>().AddSpores(amount);
}
}
The problem I’m having is I want OnMouseDown() to call AddSpores(int amount), but I’m getting errors about the arguments not matching up. I tried plugging them in in various ways but nothing seems to work. Help would be greatly appreciated!