Coding Log #1

I posted a forum not too long ago, asking what game I should start with, and I really liked the Tower Defense Idea so that's what I'm going with!!!


Waypoint navigation for the enemies;

using UnityEngine;


public class Waypoints : MonoBehaviour

{

    public static Transform[] points;

    void Awake ()

    {

        points = new Transform[transform.childCount];

        for (int i = 0; i < points.Length; i++) 

        {

            points[i] = transform.GetChild(i);


        }

    }



}

Secondly Here's my Enemy script so far! (How they move);

using UnityEngine;


public class Enemy : MonoBehaviour

{

    public float speed = 10f;


    private Transform target;

    private int wavepointIndex = 0;


    void Start()

    {

        target = Waypoints.points[0];

    }


    void Update()

    {

       Vector3 dir = target.position - transform.position;

        transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);


        if (Vector3.Distance(transform.position, target.position) >= 0.2f)

        {

            GetNextWaypoint();


        }

    }


    void GetNextWaypoint()

    {

        wavepointIndex++;

        target = Waypoints.points[wavepointIndex];

    }

}

So far I've made a functional map, with nodes that should be able to hold towers, a start and end point, and an enemy to go against the player following the pathway to the end.


1 Kudos

Comments

Displaying 1 of 1 comments ( View all | Add Comment )

Хлоя (Chloe)

Хлоя (Chloe)'s profile picture

Looks good! I love Unity.


Report Comment