Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Having Issues with my 3D Tower Defense game

Discussion in 'Scripting' started by fallenarchangel18, Oct 10, 2018.

  1. fallenarchangel18

    fallenarchangel18

    Joined:
    Oct 10, 2018
    Posts:
    2
    So... I decided that i would start trying to create a Tower defense game by following a Tutorial done by Brackeys.

    I am aware that these are old tuorials. I am on the Second tutorial where it teaches you how to make an enemy follow waypoint by using scripts. Link

    Now i followed his instructions to a T and double checked it over again. Every time i go to test to see if my Enemy is following the waypoints, the enemy doesn't move! It just sits there. There's no errors in my scripts. I don't know, maybe i need another set of eyes on these scripts?


    My Enemy Script:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Enemy : MonoBehaviour
    4. {
    5.     public float speed = 10f;
    6.  
    7.     private Transform target;
    8.     private int wavepointIndex = 0;
    9.  
    10.     void Start()
    11.     {
    12.         target = waypoints.points[0];
    13.     }
    14.  
    15.     void update ()
    16.     {
    17.         Vector3 dir = target.position - transform.position;
    18.         transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
    19.  
    20.         if (Vector3.Distance(transform.position, target.position) <= 0.4f)
    21.         {
    22.             GetNextWaypoint();
    23.         }
    24.     }
    25.     void GetNextWaypoint()
    26.     {
    27.         if (wavepointIndex >= waypoints.points.Length - 1)
    28.         {
    29.             Destroy(gameObject);
    30.             return;
    31.         }
    32.  
    33.         wavepointIndex++;
    34.         target = waypoints.points[wavepointIndex];
    35.     }
    36.  
    37. }
    38.  

    My Waypoint Script:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class waypoints : MonoBehaviour{
    4.  
    5.     public static Transform[] points;
    6.  
    7.     void Awake()
    8.     {
    9.         points = new Transform[transform.childCount];
    10.         for (int i = 0; i < points.Length; i++)
    11.         {
    12.             points[i] = transform.GetChild(i);
    13.         }
    14.     }
    15.  
    16.  
    17. }
    18.  
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    Try changing "void update ()" to "void Update ()". Capitalization matters.
     
  3. fallenarchangel18

    fallenarchangel18

    Joined:
    Oct 10, 2018
    Posts:
    2
    That was it... See... I knew i needed a second set of eyes on this. Thanks!
     
  4. zakdank

    zakdank

    Joined:
    Jan 25, 2011
    Posts:
    46
    If you are new to C#, know that methods should always start capitalized or at least, that is the general accepted rule.

    So if you see a method starting with a lowercase character, correct it.