x


having a var in one script be known to another script.

I set a var Slider: float = 0;

in one script, the mainGUI script lets say.

I want to set that variable with a slider. I can make this part work.

and then in another script ( lets say a collision ) would like that value (set by the slider) to be seen and used by the second script.

like,

function OnTriggerEnter (other : Collider) {

var setBall = GameObject.Find("steelBall"); setBall.rigidbody.drag = (Slider);

}

can any one help?

-kenm

more ▼

asked Mar 21 '10 at 10:40 PM

ken mcall gravatar image

ken mcall
31 2 2 4

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

2 answers: sort voted first

You can get the value of the slider the same way you set the drag of the steelball. Just obtain a reference to the object (e.g. using GameObject.Find), then you can access all of the variables of that object normally.

Also, you will need to set the Slider variable as public.

more ▼

answered Mar 21 '10 at 10:46 PM

Stelimar gravatar image

Stelimar
3k 14 16 50

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

I am trying to do something similar. I would like to share a hashtable with other objects. is this possible and if so could you give some simple java pseudo code?

more ▼

answered Mar 24 '10 at 09:11 PM

collypoo gravatar image

collypoo
25 2 2 8

...did not know that java is implemented in Unity? is it?

Jul 20 '10 at 02:36 PM dingben
(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:

x5096
x825

asked: Mar 21 '10 at 10:40 PM

Seen: 825 times

Last Updated: Mar 21 '10 at 10:40 PM