Z
Z
Zimaell2020-06-18 16:48:37
Game development
Zimaell, 2020-06-18 16:48:37

How is the system for building different opponents correctly built?

Tell me how the system for building different opponents is built correctly?
There should be a separate array with their data, or attach data to the prefabs ...
Explain who can or give a link to this material ...

At the moment, something similar to TD works for me, the enemy (in the plural) comes out, he has speed and life, they are taken away and removed when it reaches zero.
This is how it looks like

spoiler
public class Enemy : MonoBehaviour{
    public float speed = 1f;
    public Transform waypoints;
    private Transform waypoint;
    private int waypointIndex = -1;
    public float MaxLife = 100f;
    private float life;
    void Start(){
        waypoints = GameObject.Find("WayPoints").transform;
        NextWaypoint();
        life = MaxLife;
    	}
    void Update(){
        Vector3 dir = waypoint.transform.position - transform.position;
        dir.y = 0;
        float _speed = Time.deltaTime * speed;
        transform.Translate(dir.normalized * _speed);
        if(dir.magnitude < _speed) NextWaypoint();
        }
    void NextWaypoint(){
        ++waypointIndex;
        if(waypointIndex >= waypoints.childCount){
            Object.Destroy(gameObject);
            return;
            }
        waypoint = waypoints.GetChild(waypointIndex);
        }
    public void SetDamage(float value){
        life -= value;
        if(life <= 0) Destroy(gameObject);
        }
    }

public class Spawner : MonoBehaviour{
    public GameObject spawnObject;
    public float spawnTime = 3f;
    private float timer =0;	
    void Update(){
        timer -= Time.deltaTime;
        if(timer <= 0 ){
            Instantiate(spawnObject, transform.position, transform.rotation);
            timer = spawnTime;
            }
        }
    }

What is the best way to make it so that different types of opponents are made?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question