Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Simple C# script to follow breadcrumb trail

Discussion in 'Editor & General Support' started by thelaughingsphinX, Sep 26, 2014.

  1. thelaughingsphinX

    thelaughingsphinX

    Joined:
    Apr 17, 2014
    Posts:
    18
    Hi all,
    I come to this Forum as an artist teaching myself basic coding to create some projects. I decided not to post the script I'm using as it is a digital patchwork mess and would only take up more time pointing out where it was going wrong.
    Basically, I have a player character with a script attached which drops basic breadcrumbs (which is the underlying element of the puzzle game) and I need to have the second character follow these breadcrumbs. Nothing else.

    I've tried using GetComponent in a movement script attached to the second character to use the player character's breadcrumb script, but I'm just not getting it, and it's been over a week now, and I need help please.

    Anything would be worthwhile.
    Thank in advance . . .
     
  2. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    I would have a script on the follower guy that stores an array of the transforms of the breadcrumbs that the first guy has dropped then a navmesh or some script that always seeks the breadcrumb on the top of the arraylist. when they finally get there, use a tigger or maybe a vector3distance test to call a method that says "found it" that removes the top item on the breadcrumblist and reorders the array
     
    laurienash and thelaughingsphinX like this.
  3. thelaughingsphinX

    thelaughingsphinX

    Joined:
    Apr 17, 2014
    Posts:
    18
    Thank you for that frankrs. Would the fact that I would be using this breadcrumb data for up to 7 further following characters pose an issue?
     
  4. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    well, if you want to destroy the breadcrumb when any one gets to it you would need to send the "fount it" call to all seven of them or else you will get a null reference exception when the rest are looking for a missing breadcrumb
     
    thelaughingsphinX likes this.
  5. thelaughingsphinX

    thelaughingsphinX

    Joined:
    Apr 17, 2014
    Posts:
    18
    I see, so there is not a solution for having the breadcrumb trail remaining intact for others to follow? Well, that's plenty to get my teeth into for now, thanks again and have a good weekend.
     
  6. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    you can surely keep your breadcrumb trail, you dont have to destroy them
     
    thelaughingsphinX likes this.