Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Unodus · Dec 28, 2016 at 01:59 PM · enemyarrayslistsenemyai

How do I create a list of GameObjects & Integers?

Alright, so- first of all, I'd like to apologize because I'm not the most patient with tutorials and I'm a little rusty with Unity.

The scenario is, I want to create a system where enemy "guards" will explore a list of rooms for the player- prioritizing rooms they haven't explored in a while. I figured a way to do this was to have each Guard assign a number to each room, and increase that number while they are inside it and decrease it when they're outside it. That way, to get to the least explored room all they'd have to do is go to the room with the highest number on it (and if a guard spots a player, you could increase the number of that room so it prioritises searching that area). For references sake I refer to this number as the rooms "temperature", a guard will always go to the hottest room in order to cool it down.

So, I follow the Navmesh tutorial, bake the maze, and make a basic enemy that can navigate the maze to a target- so I figure all I need is a way to set the current target to the floor of the room the guard needs to go to and I'm good. So I tag all the floors and have a script that can find objects with that tag.

I think what I need is an array or list that holds all the rooms (there are only 9 rooms in a 3x3 grid separated by walls) as well as an integer for each room that I can increment. I've tried looking up tutorials for arrays (which are apparently outdated), lists and structures for a way of doing this. It's possible I'm not using the correct method since the main problem I'm having is trying to combine several tutorials which results in errors- so I'm not entirely sure where to start for this specific problem.

I'd appreciate any help whatsoever, this is for a college project I'm working on.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AlwaysSunny · Dec 28, 2016 at 01:58 PM

Sounds like a cool idea! I'm always disappointed by games whose agents fail to do interesting things.

It sounds like your game would benefit from a Room class. Then, your game manager or map manager stores a list of rooms. Each room can know its center, temperature, even its own shape / boundaries if you want to get fancy.

Often when you want to store multiple pieces of data that are all related, it's best to chuck them in a class. After all, a class is for handling multiple pieces of data that are all related. ;)

To satisfy the actual question in the title - assuming I comprehend what you're asking for - without a Room class, you'll be storing gameobjects (the rooms, I take it?) and integers (temperature?) in separate collections.

I still recommend a Room class for your case, but there is nothing wrong with this "separate collections" approach. I do it all the time. You must simply be consistent in how you index them. In other words, the first element of the gameobject collection must always correspond to the first element of the temperature collection.

Here are some shortcuts for syntax for declaring lists / arrays:

 using System.Collections.Generic    // required for generic lists
 public List<GameObject> myRooms;    // lists    
 public GameObject[] myRooms;        // arrays

This assumes you'll populate the arrays in the inspector. They'll already be initialized that way. If you don't expose & populate them in the inspector, you'll have to manually initialize them with code before using them.

 myRooms = new List<GameObject>();
 myRooms = new GameObject[9];

I'll leave it to you to learn how to read / write the elements.
Here's a good resource for those fundamentals:
https://www.dotnetperls.com/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Unodus · Jan 02, 2017 at 06:13 PM 0
Share

update: Thanks, managed to get past that roadblock just in time for the end of the holidays- just needed to get my head around the gameobject.getcomponent function ^^

having a room manager definitely helps, although I won't be putting the temperature in the manager- that way each individual guard checks the room they themselves checked last first, if that makes sense

thanks again!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Remembering list of camera positions is not working 0 Answers

Merging multiple array's from a specific class without manually targeting them 0 Answers

why does my enemy attack backwards? 0 Answers

How to store objects and then call them? 1 Answer

How to make all enemies attack after spawning? Not only 1. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges