- Home /
Robots Won't Spawn With Script
I'm making a shooter and I'm working on a Navigation AI for an enemy. Here's the script for it (JavaScript).
var target : Transform;
function Update()
{
GetComponent(NavMeshAgent).destination = target.position;
}
However, when i added this script to the enemy, the enemy spawning script won't cooperate with the script. Here is that script (C#).edit This is the spawning script
using UnityEngine;
using System.Collections;
public class RobotSpawner : MonoBehaviour
{
public GameObject robot;
public int respawnTime = 3;
public Vector3 spawnValues;
public int robotCount;
void Start ()
{
StartCoroutine (SpawnWaves());
}
IEnumerator SpawnWaves ()
{
while(robotCount < 0)
{
Vector3 spawnPosition = new Vector3 (Random.Range(-spawnValues.x,spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (robot, spawnPosition, spawnRotation);
yield return new WaitForSeconds (respawnTime);
}
}
}
This is really frustrating so I would l would really like help, ask any question.
What specifically isn't working? What's happening that shouldn't be, or isn't happening that should be? All you've shown us is a script that sets a destination and a script that rotates and moves... the two don't seem to reference each other in any discernible way.
just edited the post for the spawning script. I've tried to save the robot as prefab, but the transform that allows it to charge at the player won't work. I have to save the robot into the scene. However when i do that, when the main robot is destroyed, the spawned robots stop spawning.
Answer by Sabre Pilot · May 28, 2014 at 11:50 AM
AIs are extremely hard to create I don't blame you for having a problem. I have a suggestion. Copy and paste that into JS Evaluator, if it is JavaScript, it should detect any fault you have in the JavaScript and alert you once it has been checked for errors. If it is Script, I can't help you out, I want to, but I don't know Script at all. Mac Download App(Mac Descargar): JS Evaluator Mac
Windows Download(Ventanas JavaScript Evaluador):JS Evaluator Windows
I do appreciate the help, but the reason I posted this was because the prefab won't save transforms I put in to it. Therefor I had to keep the main robot in the scene, but when the main one is destroyed the others stop spawning. Do you know much about prefabs?
Answer by brickboy700 · Jun 18, 2014 at 02:06 AM
I've rewrote the script and the problem is with the prefab spawning. I recommend for future developers to finish your prefabs before saving them as such.
I'm puzzled as to why you make this recommendation. Its perfectly fine to change a prefab and hit apply to change the master prefab.