Search Unity

[help] quest journal with collectables inside

Discussion in 'Scripting' started by ThugsInMugs, Oct 12, 2015.

  1. ThugsInMugs

    ThugsInMugs

    Joined:
    Feb 8, 2014
    Posts:
    4
    So I am making a horror game like slender (but a completely different concept and story line) but I want to make a quest book/collectible book like in slender the arrival. What I really want is something like murpheys journal in silent hill downpour but slender the arrival is more known. Ive been trying to make a script but I can't for this one object can someone help? Like an outline?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Could you describe the behavior you're going for without saying "like game X"? Partly because not everyone has played the exact library of games you have, and anyone who hasn't has no idea what you want based on this post. But more importantly, describing the actual behavior desired really is key to understanding how to implement it.
     
  3. ThugsInMugs

    ThugsInMugs

    Joined:
    Feb 8, 2014
    Posts:
    4
    So its like a book GUI that starts with blank pages but as time progresses tips and quests and items that you pick up appear in the book (like documents and small notes and sheets of paper you pick up)
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    OK, so you probably want to store this as a list of a custom class. The class will contain name, description, maybe a link to a texture, etc - whatever will appear in your book. Put this class in a file somewhere outside of any other class definition (you probably want it in the book's .cs file for convenience, but it can be anywhere.) It might look like this:
    Code (csharp):
    1. [System.Serializable] //just trust me on this line
    2. public class JournalItem {
    3. public string name;
    4. public Texture2D image;
    5. public string description;
    6. }
    And in your journal, you want this:
    Code (csharp):
    1. //at the top
    2. using System.Collections.Generic;
    3.  
    4. //inside the class
    5. public List<JournalItem> allItems;
    6. void Start() {
    7. allItems = new List<JournalItem>();
    8. }
    You can access this like an array (Google for tutorials on arrays if needed), but the reason I'm using a list instead of an array is because they're easy to expand on the fly. When you want to add to it, you'll do something like:
    Code (csharp):
    1. JournalItem newItem = new JournalItem();
    2. newItem.name = "Herb";
    3. newItem.image = someHerbTexture;
    4. newItem.description = "I think this heals you";
    5. journalReference.allItems.Add(newItem);
    And this, when you want to display this, you can pull this out of your list using the index of whatever page you're on:
    Code (csharp):
    1. someUITextObject.text = allItems[currentPage].name;
    2. someUIRawImageObject.texture = allItems[currentPage].image;
    There's a lot more you can do with this, but that should get you started.
     
  5. ThugsInMugs

    ThugsInMugs

    Joined:
    Feb 8, 2014
    Posts:
    4
    Thank you so much I've been looking everywhere but couldn't find an explaination