I’m getting a really weird error that I can’t figure out. There error is:
transform.position assign attempt for ‘asteroidPrefab(Clone)’ is not valid. Input position is {3.874069, 3.855292, -Infinity}, UnityEngine.Transform.Translate(Single, Single, Single, Transform)
I have an AsteroidManager script that instantiates an asteroid prefab at one of four spawn points (empty game object). Now to be clear everything works perfectly. BUT recently I decided to reposition the spawn points slightly from on the z-axis and now I get this error. They started at 0 on the z-axis but if I move them in any positive or negative direction on the z-axis I get this error.
In case you want to see the scripts:
Here is the AsteroidManager script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AsteroidManager : MonoBehaviour {
public GameManager gameManager;
public GameObject asteroid;
public List<GameObject> asteroidSpawn = new List<GameObject>();
private int index;
// Use this for initialization
void Start ()
{
InvokeRepeating ("spawn", 4f, 4f);
}
// Update is called once per frame
void Update ()
{
}
void spawn ()
{
if (gameManager.gameOver == false)
{
index = Random.Range (0, asteroidSpawn.Count);
Instantiate (asteroid, asteroidSpawn [index].transform.position, Quaternion.identity);
}
}
}
and here is the AsteroidController script:
using UnityEngine;
using System.Collections;
public class AsteroidController : MonoBehaviour {
public GameManager gameManager;
private float xSpeed = -3f;
private float ySpeed = -3f;
// Use this for initialization
void Start ()
{
if (transform.position.x < 10)
{
xSpeed *= -1;
}
}
// Update is called once per frame
void Update ()
{
transform.Translate (xSpeed * Time.deltaTime, ySpeed * Time.deltaTime, transform.position.z, Camera.main.transform);
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Destroy (other.gameObject);
Destroy (gameObject);
GameManager.lives--;
if (GameManager.lives > 0)
{
gameManager.respawnPlayer ();
}
}
}
}