Hi, so i have a little problem, with not equal to the right variable properties.
This is the MobAI script
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(NavMeshAgent))]
public class MobAI : MonoBehaviour {
MobCreator mc;
public float health = 57f;
public float minDamage = 5f;
public float maxDamage = 10f;
public float scale = 1f;
public float attackSpeed = 1500f;
public string runAnim;
public string walkAnim;
public string idleAnim;
public bool attackable;
float distance;
int i = 0;
NavMeshAgent nma;
void Awake()
{
mc = GameObject.Find("_CREATORSCRIPTS").GetComponent<MobCreator>();
nma = GetComponent<NavMeshAgent>();
}
void Start()
{
}
// Update is called once per frame
void Update () {
distance = Vector3.Distance(GameObject.FindWithTag("Player").transform.position, transform.position);
if(distance <= 15 distance > 2f)
{
nma.SetDestination(GameObject.FindWithTag("Player").transform.position);
}
for(int i = 0; i < mc.mobCreator.Count; i++)
{
Debug.Log("For start");
health = mc.mobCreator[i].health;
minDamage = mc.mobCreator[i].minDamage;
maxDamage = mc.mobCreator[i].maxDamage;
scale = mc.mobCreator[i].scale;
nma.speed = mc.mobCreator[i].runSpeed;
attackSpeed = mc.mobCreator[i].attackSpeed;
runAnim = mc.mobCreator[i].runAnim;
walkAnim = mc.mobCreator[i].walkAnim;
idleAnim = mc.mobCreator[i].idleAnim;
attackable = mc.mobCreator[i].attackable;
Debug.Log("For end");
}
}
}
Then the mobcreator script(A script for easy making new mobs):
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MobCreator : MonoBehaviour {
[System.Serializable]
public class Mob
{
public enum MobType
{
Normal,
Elite,
Boss
}
public enum MobTypeState
{
Hostile,
Aggressive,
Friendly
}
public enum MobDamageType
{
Physical,
Ranged,
PhysicalAndRanged,
Fire,
Arcane,
Earth,
Frost
}
public string name = "Unnamed";
public float health = 57f;
public float minDamage = 5f;
public float maxDamage = 10f;
public float scale = 1f;
public float runSpeed = 4f;
public float attackSpeed = 1500f;
public GameObject mob;
public string runAnim;
public string walkAnim;
public string idleAnim;
public MobType mobType;
public MobTypeState mobTypeState;
public MobDamageType mobDamageType;
public bool attackable;
}
public List<Mob> mobCreator = new List<Mob>();
// Use this for initialization
void Start () {
GameObject mobTest = (GameObject)Instantiate(mobCreator[0].mob, GameObject.Find("MobSpawn").transform.position, Quaternion.identity);
}
// Update is called once per frame
void Update () {
}
}
Example to what i want:
I have 3 mobs in the mobcreator list, Thug, thief and rat
so i instantiate Thug, and the instantiated thug should have the variable properties from the thug in the list, but instead it does so the thug variable properties is equals to the last in the list which is the rat, so the thug has the rat properties which i don’t want, what i want is the thug has the thug properties and thief has the thief properties and rat has the rat properties, because it doesn’t really make sense if i have a thug with rat properties or a thief with rat properties
So i appreciate any help i can get, and i appreciate tips on how i could make things better.
Also a screenshot below shows the list i have of the mobs
as far as i understand the code, you constantly re-set the values in the for loop, and if i get that right, you set it to the values of mobCreator[0] up to mobCreator[2] each frame, it ends on mobCreator[2] and renders that.