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 /
avatar image
0
Question by MiroslavMilanov · Jan 18, 2018 at 06:01 PM · listenemybeginnerdatabase

Problem with adding items to a list

I'm trying to make a database of enemies for my turn based fighting game. So far I tried two things and neither worked, but I feel like this way is the better approach. If you know another method to make a database (preferably without an external source) please include it in your answer. This is my code for the database:

  using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     public class EnemyDatabase : MonoBehaviour {
         public List<Enemy> enemyList = new List<Enemy>();
         // Use this for initialization
         void Start () {
             //ENEMY CREATION
             Enemy e0 = new Enemy ();
             e0.enemyLevel = 1;
     
             e0.maxHealthPoints = 200;
             e0.maxManaPoints = 100;
     
             e0.minAtk = 10;
             e0.maxAtk = 20;
             e0.minMAtk = 0;
             e0.maxMAtk = 0;
     
             e0.phPenetration = 0;
             e0.magPenetration = 0;
     
     
             e0.armor = 0;
             e0.magRes = 0;
     
             e0.baseTime = 1;
     
             e0.critChance = 0;
     
             e0.critMult = 0;
     
             e0.blockChance = 0;
     
             e0.blockAmount = 0;
     
             e0.evadeChance = 0;
             e0.hitRate = 0;
     
     
             e0.lifeSteal = 0;
             e0.manaSteal = 0;
     
             e0.healthRegen = 0;
             e0.manaRegen = 0;
     
             e0.soulValue = 5;
             e0.goldValue = 0;
             e0.itemOdds = 0;
             e0.itemRarity = 0;
     
             enemyList.Add (e0);
             }
         
         // Update is called once per frame
         void Update () {
             
         }
     }

And this is where I use it:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;
 
 public class CurrentEnemy : MonoBehaviour
 {
     public EnemyDatabase databaseEnemy;
 
     public int enemyLevel;
 
     public int soulValue; //determines soul points you get from killing it
     public int goldValue; //determines gold you get from killing it
     public int itemOdds; //determines the odds of getting an item
     public int itemRarity; //determines the rarity of dropped item
 
     public float maxHealthPoints; 
     public float healthPoints;
     public int maxManaPoints; 
     public int manaPoints;
 
     public int minAtk, maxAtk;
     public int minMAtk, maxMAtk;
     public int phPenetration;
     //reduces oponents armor
     public int magPenetration;
     //reduces oponents magic resist
 
     public int armor, magRes;
 
     public int aSpeed; //items
 
     public int aSpeedMult; //skills, passives
     public float baseTime; //weapon
     //base interval of attacks
     public float atkTimer;
     //atkTimer=base*aCoef
 
     //>100 => %
     public int critChance;
     //float critChance 0-100
     public int critMult;
 
     public int blockChance;
     //Same as crit
     public int blockAmount; //shield, weapon
     //0-100
     public int evadeChance;
     public int hitRate;
     //reduces oponents evasion
 
     public int lifeSteal, manaSteal; //skills, passives, items
 
     public int healthRegen;
     public int manaRegen;
 
 
     public void LoadEnemy(){
         int index=0;
         Debug.Log (databaseEnemy.enemyList.Count ());
         for (int i = 0; i < databaseEnemy.enemyList.Count (); i++) {
             if (databaseEnemy.enemyList [i].enemyLevel == enemyLevel)
                 index = i;
         }
         Debug.Log (index);
         maxHealthPoints = databaseEnemy.enemyList [index].maxHealthPoints;
         maxManaPoints = databaseEnemy.enemyList [index].maxManaPoints;
 
         minAtk = databaseEnemy.enemyList [index].minAtk;
         maxAtk = databaseEnemy.enemyList [index].maxAtk;
         minMAtk = databaseEnemy.enemyList [index].minMAtk;
         maxMAtk = databaseEnemy.enemyList [index].maxMAtk;
 
         phPenetration = databaseEnemy.enemyList [index].phPenetration;
         magPenetration = databaseEnemy.enemyList [index].magPenetration;
 
         armor = databaseEnemy.enemyList [index].armor;
         magRes = databaseEnemy.enemyList [index].magRes;
 
         baseTime = databaseEnemy.enemyList [index].baseTime;
 
         critChance = databaseEnemy.enemyList [index].critChance;
         critMult = databaseEnemy.enemyList [index].critMult;
 
         blockChance = databaseEnemy.enemyList [index].blockChance;
         blockAmount = databaseEnemy.enemyList [index].blockAmount;
 
         evadeChance = databaseEnemy.enemyList [index].evadeChance;
         hitRate = databaseEnemy.enemyList [index].hitRate;
 
         lifeSteal = databaseEnemy.enemyList [index].lifeSteal;
         manaSteal = databaseEnemy.enemyList [index].manaSteal;
 
         healthRegen = databaseEnemy.enemyList [index].healthRegen;
         manaRegen = databaseEnemy.enemyList [index].manaRegen;
 
         soulValue = databaseEnemy.enemyList [index].soulValue;
         goldValue = databaseEnemy.enemyList [index].goldValue;
         itemOdds = databaseEnemy.enemyList [index].itemOdds;
         itemRarity = databaseEnemy.enemyList [index].itemRarity;
     }
 
 
     void Start ()
     {
         enemyLevel = 1;
         LoadEnemy ();
     }
 
 
 
     // Update is called once per frame
     void Update ()
     {
         if (healthPoints < 0)
             healthPoints = 0;
     }
 }

I'm getting the following console error: alt text I think my List is empty. I followed a guide where the person initialized the List like this: public List enemyList = new List(); And the enemies : Enemy e0 = new Enemy (); I don't know if this is right, but it worked for him. Again, if you know a better approach, please share. Thank you very much!

cd7fe6df87b7c29025153cc233f21c09.png (35.7 kB)
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 dev-waqas · Jan 18, 2018 at 08:47 PM

Most probably its because of script execution order. You want to make sure your script CurrentEnemy should execute after EnemyDatabase so you should set order of scripts in following window. alt text


untitled.png (82.4 kB)
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 MiroslavMilanov · Jan 19, 2018 at 02:23 PM 0
Share

It did fix the problem, thank you very much! Are there any other important bits like this that I should know before committing to a large project?

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

84 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

Saving Data (closed) 1 Answer

how to split TextAsset into a Dictionary? 0 Answers

List of custom classes in MonoBehaviour's Data gets lost after Re-Opening Unity!!! 0 Answers

Enemy list wont update 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