I’m making a bullet-hell like game and am having problems spawning enemies
So I have this EnemySpawn script which takes in a type of enemy and spawns it.
void Spawn()
{
GameObject newEnemy = (GameObject)Instantiate(Enemy);
}
Attached to the enemy is a WaypointMovement script which uses ITweens MoveTo function.
It compiles properly and all but Unity is giving me this a error (NullReferenceException: Object Reference not set to an instance of an object).
It happens on the LateUpdate and the TweenUpdate of ITween.
EDIT:
It happens on line 4624 and 6598 of iTween.cs (The first line of TweenUpdate() and LateUpdate() respectively)
Welp!
EDIT:
Well, my Enemy gameobject only has my WaypointMovement script attached to it.
Here is my WaypointMovement script.
using UnityEngine;
using System.Collections;
public class WaypointMovement : MonoBehaviour
{
public Transform[] waypoints;
public int rate = 20;
private int currentWaypoint = 0;
void Start()
{
MoveToWaypoint();
}
void MoveToWaypoint()
{
//Get the time it takes to travel with the distance and rate
float t = Vector3.Distance(transform.position, waypoints[currentWaypoint].position) / rate;
//Get iTween to apply the movement to the object
iTween.MoveTo(gameObject, iTween.Hash("position", waypoints[currentWaypoint], "time", t, "easetype", "linear", "oncomplete", "MoveToWaypoint", "Looktarget", waypoints[currentWaypoint].position, "looktime", .4));
//Set the currentWaypoint to the next one
currentWaypoint++;
//Start from the first again
if (currentWaypoint > waypoints.Length)
{
currentWaypoint = 0;
}
}
}
EDIT:
This enemy has the WaypointMovement script attached to it.
The enemy works fine when I manually place them onto the scene.
However, it gives me a null reference error when I try to spawn a new enemy using the Spawn() in my EnemySpawn script.
EDIT:
This is what happens when I use my spawn function.
