x


setting max varible value

i was just wandering how you make a maximum varible float number in unity. not during runtime but in editor, so basically i could set a max and min to 1,10 and i would not be able to go past that in the inspector

cheers

more ▼

asked May 13 '12 at 01:59 AM

reptilebeats gravatar image

reptilebeats
1.2k 57 108 137

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

3 answers: sort voted first
more ▼

answered May 13 '12 at 05:32 AM

Samuel gravatar image

Samuel
28 4 5 9

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

I found a good hack for this: if you put the Mathf.Clamp() function in the OnDrawGizmos override, it'll get called in the editor without having to mess with the rest of your script. It works great for me!

more ▼

answered Mar 28 at 03:32 PM

mysteriosum gravatar image

mysteriosum
1

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

Look up for Mathf.Camp, that should make it.

This has been asked many times: Example. Please google it next time.

more ▼

answered May 13 '12 at 02:01 AM

Noah 1 gravatar image

Noah 1
1.1k 33 45 50

Looks like they're asking about inspector-specific clamping, not only inside the script. To where if you try to change something clamped between 0 and 5 in code, to 532340934 in the inspector it won't allow it.

May 13 '12 at 02:06 AM Lo0NuhtiK

yes im just asking about the inspector clamping, i dont have much knowledge of making scripts outside of runtime if you know what i mean.

i can set max and mins when game is running but would like to be able to do it when game isnt running for my own benifit.

May 13 '12 at 02:10 AM reptilebeats

You could still do it with clamp and having your script run in edit mode. Only thing that sucks about that is it will run all the other stuff in your code also.

May 13 '12 at 02:30 AM Lo0NuhtiK

yep just fond that edit line, shame it cant be set as a function, i just tried mathf but wouldnt work just set it to the first number. when i set it in if's it works.

i might be using it wrong i never use math operations, i had something like

pragma strict

@script ExecuteInEditMode()

var alphaAmount : float;

function OnGUI(){

alphaAmount = Mathf.Clamp(1,0.05,0.5);

}

May 13 '12 at 02:55 AM reptilebeats

doesnt matter had to put alpha in as my value

May 13 '12 at 03:08 AM reptilebeats
(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:

x3889
x185
x117
x18

asked: May 13 '12 at 01:59 AM

Seen: 1235 times

Last Updated: Mar 28 at 03:32 PM