x


C# Unity 3D Using functions from other files.

Having trouble figuring out how to use other C# files with my other C# files, can anyone help me getting this to work.

more ▼

asked Jan 26 '12 at 12:31 PM

jimkiller12 gravatar image

jimkiller12
16 5 6 8

If your other file is attached to a game object, then tag this game object and use:

GameObject.FindGameObjectWithTag("sometag").GetComponent < NameOfYourScript > ().NameOfYourFunction();

Jan 26 '12 at 12:51 PM cj_coimbra
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

If you are trying to access an instance of a script, I'll quote cj.coimbra :

GameObject.FindGameObjectWithTag("sometag").GetComponent < NameOfYourScript > ().NameOfYourFunction();

If you want to use a class from another file *.cs, well, nothing special here, just call the class as if it was one file. Not sure if it was your question, maybe you're looking for something static ?

more ▼

answered Jan 27 '12 at 01:53 AM

Berenger gravatar image

Berenger
11k 12 19 53

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

x4171
x3742
x67
x15

asked: Jan 26 '12 at 12:31 PM

Seen: 761 times

Last Updated: Jan 27 '12 at 01:53 AM