Creating an asteroid and ground object that resources can be collected form

I have been unable to to find any tutorials on how to create a harvest script for a harvestor unit that would be able to extract resources from the following three model types.

  1. Resrouce collection points on an asteroid.
  2. Resource collection points on a planetary surface.
  3. Reseource collection points within a cloud.

Basically the function would be that the harvestor would be selected to auto harvest by pressing a definable key that would then direct the harvester to the closest mineable object being the asteroid.

When the harvester was directed to harvest a cloud or planetary surface I would most likely need to add a sphere collider with a various radius that when the harvester triggered the sphere the harvester would be told to search within the spheres form secondary sphere colliders from that would contain the actuall resource units wanting to be collected.

After one mineable zone had been depleted the harvestor would then move onto the next mineable zone.

Does anyone know of any tutorials that will guide me along the process of creating the harvestor that when the letter H is pressed the above events will occur?

The first thing I think of when I read this is state machine.

I would advise you get your harvester working on asteroids first. Detecting the H key being pressed is a piece of cake;

public class InputController : MonoBehaviour
    Harvester[] selectedHarvesters;  // this may need to be a list, but the sites formatting makes me not even want to bother with the < > stuff...

    void Update()
        if (Input.GetKeyDown(KeyCode.H))
            foreach (Harvester h in harvesters)

public class Harvester : MonoBehaviour
    private Resource targetResource;

    public void Harvest()
        targetResource = FindClosestResource();
        // go to it and do your thing...

    Resource FindClosestResource()
        Resource[] resources = Component.FindObjectsOfType(typeof(Resource)) as Resources[];
        resources.OrderBy(r => Vector3.Distance(transform.position, r.transform.position));
        return resources[0];

What I’ve written here is just a basic script to get you pointed in the right direction. You’re going to need to include System.Linq in your Harvester class…that is if you’re using C#. If not, you’re going to have to order your Resources the old fashioned way. :slight_smile:

Good luck, and post back with some specific questions! Get those asteroids mined!