Hey guys,
I’m running into a problem. I have a script which instantiates a prefab, like this:
public class SegmentScript : MonoBehaviour {
public GameObject bar_piece;
private int start_height;
private int end_height;
private int score;
private GameObject[] pieces;
private Vector3 start_location;
// Use this for initialization
public void Start () {
pieces = new GameObject[10];
AddPieces(start_height, end_height);
}
public void AddPieces(int start, int end){
for(int i = start;i<end;i++){
Vector3 piece_location = start_location;
piece_location.y = i;
GameObject new_piece = Instantiate(bar_piece, piece_location, Quaternion.Euler(0,0,0)) as GameObject;
pieces *= new_piece;*
}
}
}
Now, when I select the script in the inspector, I can drag and drop a prefab to the bar_piece slot. During runtime, I add this script through another script using the AddComponent function.
But somehow the prefab slot for bar_piece is empty again and I get the ArgumentException.
The weirdest part is that another script uses the exact same method to instantiate an object, but that works fine.