So I am trying to make a script that takes enemies from a list of Scriptable objects, and places them in a “currently in battle” list of monsters for combat. [Making a jrpg for school.]
and I cant seem to get it working. here is what I have so far:
I have my enemy object SO:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Enemy", menuName = "Enemy")]
public class EnemyObject : ScriptableObject
{
public string enemyName;
public float HP;
public float MP;
public float baseStrength;
public float baseSpecialStrength;
public float baseSpecialDefense;
public float baseDefense;
public float baseSpeed;
public Sprite enemyImage;
}
My list of SO enemies:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "EnemyGroup", menuName = "EnemyGroup")]
public class EnemyGroups : ScriptableObject
{
public List<ScriptableObject> EnemyGroup;
}
and my enemyMain monobehavior, Is currently the script I want to put the data from the SO list into the new SO list of monsters to spawn into the battle.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMain : MonoBehaviour
{
private EnemyObject enemy;
public EnemyGroups listWriter;
private List<EnemyObject> spawnableEnemy = new List<EnemyObject>(4);
public string currentEnemyName;
public float currentHP = 0;
public float currentMP = 0;
public float currentBaseStr=0;
public float currentBaseSpecStr=0;
public float currentBaseSpecDef=0;
public float currentBaseDefense=0;
public float currentBaseSpeed=0;
public Sprite enemyImage;
void Start()
{
listWriter.EnemyGroup[0] = spawnableEnemy[0];
currentEnemyName = enemy.enemyName;
currentHP = enemy.HP;
currentMP = enemy.MP;
currentBaseSpecStr = enemy.baseSpecialStrength;
currentBaseSpecDef = enemy.baseSpecialDefense;
currentBaseDefense = enemy.baseDefense;
currentBaseSpeed = enemy.baseSpeed;
}
// Update is called once per frame
void Update()
{
}
}
To dissect what might be happening, since you know what you WANT to have happen, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
is this code even running? which parts are running? how often does it run?
what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
If you are running a mobile device you can also see the console output. Google for how.
What would you need for it to be helpful? I’ll try debug logs and stuff, but I’ve been banging my head against this wall for a 12 hours, and I don’t feel like it should be this hard haha I’m seemingly RIGHT there
I seem to have done everything in the link except for ‘Tell us where the bug is’, and if I knew that, I wouldn’t be posting to a forum, but I do believe the problem lies in
istWriter.EnemyGroup[0] = spawnableEnemy[0];
Which I’ve tried MANY complex and simple variations of. This line was more to see if they communicated at all, which they don’t seem to be. before the code was multiple steps of, taking out a random scriptable from EnemyGroup list, and assigning it a spot in the spawnable list.
Start with that. Make a method that Instantiates the enemy.
When that works, stop, commit it to source control.
Now move that into a ScriptableObject that has some parameters about the enemy: which enemy and how many to make.
Make an instance of it, make a little test harness to drive it, test it.
When that works, commit to source control.
Now change your little harness to spawn one set of enemies from SO #1, then when they are all destroyed, do it from a second SO #2.
When that works… yep, commit to source control.
Now you have the rudiments of the system and you can begin to reason about some kind of game-length-lived manager that will take a list of SOs and do the above already-functioning thing.
Iterate, iterate, iterate, and at each step, commit to source control.
You will NEVER get a complicated system working like this without iterating. You must take one step at a time. Seriously. One step.
Thank you! I should mention I am an art student, transitioning into technical art in college and I’ve only been using c# about 3 months. So I’m sure this was a little ambitious, but I do understand what you’re saying! I just definitely lacked the experience to get there. I will look into how to better break down my code and iterate. any literature you know of would be welcome [: