- Home /
Can't Assign 3DText to the script
Hello guys , first of all please understand I'm still new to Unity and I know my question maybe a little obvious, I made a 3dtext named "Score_Text" which is suppose to get score +100 every time the cannon balls hits the target , The problem is I cant assign the 3dtext to the actual script, I checked my script uncountable times since 3 days and no use I tried everything that could be the problem, here is a screeshots for my problem with the script :
Thanks In Advanced for help.
if you're posting a script, post the script contents and not a screenshot of it. if's easier to read and, where necessary, can be pasted into unity to help somebody help you. nobody is going to retype something from a screenshot.
a screenshot would be helpful to show the other components attached to the game object that your script is also attached to.
also, there's no need to put all your text in bold either, you might as well use ALL CAPS if you're attention seeking...
$$anonymous$$y Apologies I didn't mean attention seeking I just prefer bold writing because I feel more comfortable reading it ... I will Upload the whole project (1 mb) If you can help thanks in advanced :)
Sadly I couldn't upload my file I don't know why but it wont allow me ...
Answer by Owen-Reynolds · Nov 27, 2014 at 12:36 AM
Don't use the pop-up to assign Inspector gameObjects. Instead drag your Score_Text into the Inspector slot.
The pop-up is really useful for things like Textures and Materials. But, it only looks at your Assets. In this case, it would only find created prefabs, since those are assets. It won't show you gameObjects in the scene.
In general, you can drag anything into an inspector slot (instead of using the pop-up.) Often you know where it is already, so dragging is just easier. The pop-up is good for when you know you have a "wood" texture, but can't remember where.
Thanks for replying to my question , the problem is even when I drag Score_text to inspector it wont be assigned to ball script ...
Is your 2nd picture correct? Are you using the ballScript in Assets? Ins$$anonymous$$d of that, a real gameObject should have ballScript on it, then select that gameObject.
"$$anonymous$$onobehavoiur" scripts are always meant to be used that way -- add them to a gameObject. Otherwise they aren't in the scene, and won't run. The only reason they even show slots for the script in Assets is for a rare shortcut using prefabs.
The ball is shooting correctly by another script called cannon , the only thing written in ball script is when it hits the target it shall gives +100 score .
So the ball is a prefab? Prefabs can't have links to non-prefabs (they aren't part of the scene, so can't know about anything in the scene.)
Can either use GameObject.Find, or have the cannon script assign the var, after the Instantiate.
Thanks so much for your help , I fixed my problem after 4 long days , thanks again :)
Your answer
Follow this Question
Related Questions
assign wheel collider through script 1 Answer
Variable not Assigned 1 Answer
Changing the colour of a 3DText through script gives a weird error 0 Answers
How do I assign a script to a clone through another script? 1 Answer
How Unity assigns image effect shaders to their scripts automatically? 1 Answer