Hello everyone I need some help. For you will be easy to fix but I’m trying in every possible way not accomplish much. What I want to do are these Christmas balls that fall from the top tray to random (and up to far so good) also these balls (made up of 3 components: 1 ball and 2 hooks) change color every second and I have to click with your mouse over the red ball to gain points. At first I made two scripts: the first script was connected to the chamber and was used to instantiate objects. The second script was used to change color at random and was linked to item 1 of the ball (the ball). I found myself in trouble, however, to pass the array of textures in the main room. I finished the idea in this way:
var speed : int = 2;
var chrismasBall : GameObject; //GameObject
var instanza; //instanza
var texBall : Texture = new Texture [5]; //Array di texture
function Start () {
StartCoroutine(Creation(1)); //Coroutine
var finds = GameObject.Find(“snow_ball”); // trova tag e assegno a finds
Debug.Log(finds); // stampo l’oggetto in console
instanza.GetComponent(main).textureRandom();
}
function Update () {
Physics.gravity = Vector3(0, -0.05, 0); // aggiungo gravità
}
function Creation(tempo){
while(true){
instanza = Instantiate (chrismasBall, transform.position, Quaternion.identity); //instanza chrismasBall
instanza.AddComponent(Rigidbody); //aggiungo rigidbody alle instanze
instanza.transform.position.x = Random.Range(2,-2); //raggio di instanza
instanza.transform.position.y = 2;
instanza.transform.position.z = 0.2; //distanza dalla Main Camera
instanza.transform.Translate(0, Time.deltaTime, 0);
yield WaitForSeconds(tempo);
}
}
function textureRandom(){
while(true){
yield WaitForSeconds(1); //aspetto 1 secondo e cambio colore alla mesh
var randomtex; // variabile randomColor
randomtex = texBall[Random.Range(0, texBall.length)]; //random della variabile cambiaColore
renderer.material.mainTexture= randomtex; // lo assegno alla variabile randomColor
}
}
But me error on line 15 saying:
Object reference not set to an instance of an object
Someone is kind enough to help me? thank you