x


calculate things... and display in inspector

so, i have a script (js) like that:

var a;
var b;

var c;
c = a + b;

after i attach this script to an object, i wonder if there is any way in that if i change the values of a or b, to see the new "c" in inspector... some kind of input text for a and b and dynamic text for c.

more ▼

asked Jun 09 '10 at 09:29 PM

hyper gravatar image

hyper
21 2 2 8

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

3 answers: sort voted first

Try playing around with ExecuteInEditMode.

So like this:

@script ExecuteInEditMode()

var a;
var b;
var c;

void Update()
{
    c = a + b;
}

(I haven't tested this.)

more ▼

answered Jun 09 '10 at 10:14 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

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

As unity does not display properties with getters/setters, your best bet would be writing a custom inspector.

more ▼

answered Jun 09 '10 at 10:10 PM

Ricardo gravatar image

Ricardo
5.2k 20 32 96

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

yep, this is working! thanks!

i just added the var types for a,b,c, i get some errors if not... here is the javascript version:

@script ExecuteInEditMode()

var a:float;
var b:float;
var c:float;

function Update() {
    c = a + b;
}
more ▼

answered Jun 10 '10 at 01:01 AM

hyper gravatar image

hyper
21 2 2 8

(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:

x1663
x816
x463
x56

asked: Jun 09 '10 at 09:29 PM

Seen: 1020 times

Last Updated: Jun 09 '10 at 10:12 PM