Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
avatar image
0
Question by MontyB · Aug 10, 2015 at 01:32 PM · prefabsvariableslists

Increasing through a list after an object has been destroyed

Recently, I've been working on an educational FPS game - once you 'tag' an enemy (Destroy(GameObject) etc on a prefab that's spawned on level load), the idea is that a variable will increase through a list of preset sums which is going to be displayed.

The one problem I've come across, is having the list count be increased after the correct enemy (each is named with their answer, e.g. EnemyNumber1, EnemyNumber2 etc). This is the last thing I have yet to code and I'm come across a blank.

Basically, I want to increase through a list after a certain prefab has been destroyed. This would then be put into another variable to track it and used to output to a text line. Does anyone have any advice for this specific thing?

Thanks.

Comment
Add comment · Show 3
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 Demonicdaron · Aug 10, 2015 at 01:41 PM 0
Share

What do you mean by this sentence:

"I want to increase through a list after a certain prefab has been destroyed"

specifically, what do you mean by "increase through a list"?

avatar image MontyB · Aug 10, 2015 at 01:50 PM 0
Share

I have a list of GameObjects, ins$$anonymous$$d of an array (but it basically functions as a 1D array - I'm using C# by the way). In essence, I want to destroy a certain prefab, causing the list to move onto the next string and for this to be displayed.

Thanks.

avatar image Pharaoh_ · Aug 10, 2015 at 02:10 PM 0
Share

It's not really clear to me, but if you increase an int every time this happens and then use the respective index from the List? Debug.Log(GOList[index].name);

2 Replies

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

Answer by stepan-stulov · Aug 17, 2015 at 03:11 PM

From your very blurry description I think what you want is to store a count of destroyed enemies grouped by their names. A'la: I have destroyed 3 Joes and 5 Bens.

Here is what you can do:

 public class DestroyedEnemyEntry
 {
    public string name;
    public int count;
 }
 
 // Later
 
 private Dictionary<string, DestroyedEnemyEntry> _destroyedEnemyEntriesByName = ...;
 
 // Later
 
 _destroyedEnemyEntriesByName["Joe"] = new DestroyedEnemyEntry("Joe", 0);
 _destroyedEnemyEntriesByName["Ben"] = new DestroyedEnemyEntry("Ben", 0);
 
 // Later
 
 string destroyedEnemyName = /* However you communicate named enemy destruction */;
 _destroyedEnemyEntriesByName[destrioyedEnemyName].count ++;
 Debug.Log(string.Format("There have been {0} of {1}s destroyed", _destroyedEnemyEntriesByName[destrioyedEnemyName].count.ToString(), destrioyedEnemyName));
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 MontyB · Aug 19, 2015 at 09:44 AM 0
Share

Thanks!

avatar image
0

Answer by Chrisasan · Aug 17, 2015 at 03:11 PM

Check if the gameObject is true, if it is true then you can perform work on it, if it is false, then move on and not do any work on it.

public var arr : GameObject[];

for(var scan=0;scan < arr.length;scan++) { if(arr[scan]) {... work on it}

}

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scripts/buttons getting old (prefab?) values of variables 1 Answer

Prefab Script List not being assigned as unique - can you see why? 1 Answer

Create customizable vehicles ingame with prefabs? 0 Answers

How many variables can i have of type 'Prefab' in a scene at one time? 1 Answer

Set variables from a prefab 0 Answers


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