The question is answered, right answer was accepted
Problem with c# script
Hi! I'm following a TD game tutorial and I encountered error I can't fix myself. link to guide - https://www.raywenderlich.com/107525/create-tower-defense-game-unity-part-1
I'm at - Check That It All Works
This is error I get in console - NullReferenceException: Object reference not set to an instance of an object SpawnEnemy.Start () (at Assets/SpawnEnemy.cs:12)
I'm very new to unity so expect mistakes average users wouldn't make.
Script with an error:
using UnityEngine; using System.Collections;
public class SpawnEnemy : MonoBehaviour {
public GameObject[] waypoints;
public GameObject testEnemyPrefab;
void Start()
{
Instantiate(testEnemyPrefab).GetComponent<MoveEnemy>().waypoints = waypoints;
}
}
Do you have all the GameObjects assigned in the Unity inspector?
Yes. When I put "enemy" nothing appears - http://scr.hu/6sn8/nzns4
but when I put child of enemy (sprite) in appears in the middle of map - http://scr.hu/6sn8/w1dnq
Copy and paste your script on your question. The link you gave seems to have already expired, I'm seeing a 404.
Updated question and here's new link http://scr.hu/6sn8/n18ix
have you attached the $$anonymous$$oveEnemy script to the Enemy prefab ?
This was a problem. Fixed it. Thanks for help.
Follow this Question
Related Questions
Finding the max Y position value in a list of game objects and assigning it to a variable? 0 Answers
Grading system not working 1 Answer
Running C# Function from JS file 0 Answers
Hololens sharing example 1 Answer
Why can't I call a function within the same class? (Or: how does unity handle instancing?) 0 Answers