bad englis incoming
Hi everyone. I’m sperimenting things in unity this time. I’m creating a 2d game where there are many casually generated shapes and similiars in the scene and you have to do things with 'em.
To made the thing simple, i’m using prefabs of planes rotated in the right way with textures of what they represent.
To renderize 'em I use this c# script, attached to the camera:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class Prova : MonoBehaviour
{
List<Transform> oggetti = new List<Transform>();
public Transform cerchio;
public Transform triangolo;
public int difficolta;
bool primoLoop;
public GameObject daRenderizzare = null;
// Use this for initialization
void Start()
{
difficolta = 2;
oggetti.Add(cerchio);
oggetti.Add(triangolo);
primoLoop = true;
}
// Update is called once per frame
void Update()
{
System.Random random = new System.Random();
List<GameObject> roba = new List<GameObject>();
int oggetto;
int oggettiInscena = random.Next(2, difficolta);
for (int i = 2; i < oggettiInscena; i++)
{
int xPos = random.Next(-160, 160);
int yPos = random.Next(-75, 60);
Vector3 posizioneOgg = new Vector3(xPos, yPos, 5);
oggetto = random.Next(0, difficolta);
daRenderizzare = (GameObject)Instantiate(oggetti[oggetto], posizioneOgg, Quaternion.identity);
}
//code here that doesn't let the system torecreate the shapes at every frame
primoLoop = false;
}
}
ignore all the variables written in italian: code is still code even written in japanese (nothing aganist nihonjin).
Anyway what the code does (OR AT LEAST: what i’d want it to do but looks like i missed something) is that when i run the game, shapes comes out at random from the list and i can do what i want. But when i run the game, there is the background i pre-created but not the shapes. And that’s not because they’re not visible for a choordinate mistake because the inspector doesn’t show 'em at all.
The script doesn’t contai errors.
The prefabs, which i keep on a folder called Resources, contains the prefabs.
what kind of prefab to use for cerchio and triangle is declared in the inspector of the camera (i drag the prefab into the desidered slot of the script dedicated session).
So am i missing something (maybe i did some mistakes in the list declaration but i’m not sure (however i used simple arrays before for the same purpose and i had the same error))? How do i fix it?
Many thanks from now.
Regards, asduffo.