Hello, I’m completely new to Unity, and I’m currently trying to get this going.
A 3D-model which can be rotated (this seen from any angle), the model contains many objects. When you click on a particular object it’s name should be displayed.
I’ve a Mousedown script working (when you click the mouse (any were in the scene) it displays some text in the debug. Now I want the message only to display when I click on the object and to display that text somewhere at a fixed position onscreen.
Can somebody help me?
BTW I’m I doing good with the Mousedown or should I make the objects some type of button first?
Your doing good with the mousedown, but you need a mouse down on each object that you want to click on. Then reference it back to the gui on the screen.
// code attached to your camera
// name this script "myGUI"
var txt = "";
function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), txt);
}
// code attached to all of your objects
function OnMouseDown () {
Camera.main.gameObject.GetComponent("myGUI").txt = transform.name;
}
Thank you BigMisterB, it works like a charm!
Now I’m off to get it updating a list (highlighting the clicked on object name in a list). I’m trying to get it to do by myself or otherwise you’ll see a new thread on this great forum pretty soon;-)
This script worked great up until now. I’m working with iOS now and when I’m trying to build I get the following error:
BCE0019: ‘txt’ is not a member of ‘UnityEngine.Component’.
I’ve search the forum and it has something to do with building for iOS (I think) and that the script has to be rephrased.
I’ve added “#pragma strict” already so I get the error already when saving the script instead only when building.
Anybody any ideas?
Edit 1: I’ve changed it into:
var txt : String = “”;
Since I read somewhere this requires strict annotation so I explicitly stated that txt is a string, but unfortunately it didn’t solve the problem. SO any help is appreciated
Edit 2 I’ve changed
Camera.main.gameObject.GetComponent(“myGUI”).txt = transform.name;
into:
(Camera.main.gameObject.GetComponent(myGUI) as myGUI).txt = transform.name;
which solved the error and the script works fine again. This seems the exact “strict” typing which was required.
I think you might have accidentally replied to this thread when you meant to post a new one. (You can post a new thread using the ‘Post New Thread’ button at the top of each forum page.)