x


How to make a Custom inspector?

The simple question is how to make a custom inspector.

The long(er) version is I have difficulty understanding the principles behind it. I need the inspector to get data from a script based on an input field from the same inspector. The altered information should automatically be save when i hit enter. (I figure i just can use GUI.changed)

The Image is the GUI only and none of it have any functions to it yet.

Can anyone help me?

How do I in JavaScript:

  • Get Variables from another script (in another folder)
  • Save data to that script again so it persist
  • make a new script from the inspector just by hitting a button. (Maybe a prefab of the script, then copy it and edit the new one?)

alt text

more ▼

asked May 16 '12 at 04:13 PM

Andr gravatar image

Andr
2 2 2 3

In c# to acces a variable in another script you do : NAMEOFTHESCRIPT.VARIABLE

May 16 '12 at 07:33 PM hesa2020

Sorry didnt mention it should be in JS. Is it worth learning C#, it looks like most things is fairly easy in C#

May 16 '12 at 07:42 PM Andr
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I can help with the first two parts...

To access and save variable data from another script, you should have that script attached to something in your scene. Just one copy of it.

Use this line:

var otherScriptObject : GameObject;

Drag that object into that variable in the inspector. You can also find it using GameObject.Find(), but this is the easiest way.

Then find that script from your first one with this line:

var otherScript = otherScriptObject.GetComponent("nameOfOtherScript");

Then you can refer to variables (and functions) in that script like this:

otherScript.someVariable = 3.14;
otherScript.someFunction();
more ▼

answered May 16 '12 at 08:18 PM

Tasarran gravatar image

Tasarran
1.1k 12 21 27

(comments are locked)
10|3000 characters needed characters left

If I understand part 3, you want to make a new script onto an game object? That's AddComponent()

more ▼

answered May 17 '12 at 02:47 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3682
x1671
x31

asked: May 16 '12 at 04:13 PM

Seen: 604 times

Last Updated: May 17 '12 at 02:47 AM