Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by chucky831 · Dec 13, 2012 at 07:57 PM · texturearraycomponent

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image svenskefan · Dec 14, 2012 at 10:14 AM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BiG · Dec 14, 2012 at 12:38 PM 0
Share

@$$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)!

avatar image $$anonymous$$ · Dec 14, 2012 at 12:48 PM 1
Share

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.

avatar image BiG · Dec 14, 2012 at 12:53 PM 0
Share

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! ;-)

avatar image
0

Answer by chucky831 · Dec 15, 2012 at 01:54 PM

ciao @Neurological come posso contattarti? non trovo l'opzione per i messaggi privati =)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges