- Home /
How do I fix this error?
I am making a 2d Infinite Runner game and was making a script for the spawn pads to generate. I have no idea how to fix the error.
The error: Assets/Scripts/SpawnScript.cs(18,29): error CS0178: Invalid rank specifier: expected ,' or
]'
Also: Assets/Scripts/SpawnScript.cs(23,1): error CS8025: Parsing error
The script is:
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;
// Use this for initialization
void Start () {
Spawn ();
}
void Spawn ()
{
Instantiate(obj[Random.Range 0, obj.GetLength(0))], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
}
}
If anyone could help, that would be awesome. Thanks.
Comment
Answer by PAHeartBeat · Oct 01, 2014 at 06:57 AM
Hi
Your Code:
void Spawn ()
{
Instantiate(obj[Random.Range 0, obj.GetLength(0))], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
}
First error:
Instantiate(obj[Random.Range 0, obj.GetLength(0))], transform.position, Quaternion.identity);
change to
Instantiate(obj[Random.Range 0, obj.GetLength(0)], transform.position, Quaternion.identity);
Second error: remove second curly brace
Your answer
Follow this Question
Related Questions
Error line 22! Help. i dont know why? 1 Answer
(C#) Problem with animations not playing 1 Answer
Error Code BCE0044 1 Answer
Error in script I haven't even opened 0 Answers
Unity Script Editor Not Working 1 Answer