- Home /
problem with FindWithTag
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
Hi! So what is line 15?
The gist of the message is that you are trying to use some variable that for some reason doesn´t contain what you expect it to contain. Could be several reasons for that.
Answer by $$anonymous$$ · Dec 14, 2012 at 12:29 PM
Which line give you the problem, var chrismasBall : GameObject;? In the title you put FindWithTag, but I can't see it in the code anywhere.
By the way, try to format the question a little better, the whole code is not very readable. On this line:
var finds = GameObject.Find("snow_ball"); // trova tag e assegno a finds Debug.Log(finds);
This way doesn't find the tag, but only the object name in the scene, for the tag you have to search with FindWithTag, like you put in your question title.
@$$anonymous$$: we (you, chucky831 and I) are italians (and I'm happy to know that!), but the site is not for "private" discussions! If you want to speak in Italian with the OP, I suggest to compile the profile with your contacts, so that you can be reached with private messages. Until then, please, speak english here! Thank you (on behalf of the community)!
Yeah sorry, considering the question itself looks like done with google translator just wanted to be clear with him as he may not know english so good. By the way edited the answer in english.
Thanks! If that was the reason, you can always give a "double-language" answer (if that would be of some utility...The OP could always use Google Translate by itself!); I don't think that it wouldn't be allowed.
Seems that someone downvoted your answer, for that reason: I kindly ask him to retract the downvote, since Neurological has edited the answer! ;-)
Answer by chucky831 · Dec 15, 2012 at 01:54 PM
ciao @Neurological come posso contattarti? non trovo l'opzione per i messaggi privati =)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
script communicate with each other 0 Answers
Trying to switch Textures on object based on timer 2 Answers
Will not create the array 0 Answers
How to get a value from an array within another script. 1 Answer