x


How can i get a Transform component from an other object's script?

I have a Player and a Mob gameobject. I want to get the Player's Target component to the Mob's PTarget. My player's script what does the targeting is called "Targeting". How can i acces this?

more ▼

asked May 06 '12 at 07:01 PM

hyderox gravatar image

hyderox
21 3 8 11

I didn't downvote your question, but... this is a joke, right?

May 06 '12 at 07:30 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Under the Mob's script you can use the following (c#):

Transform PTarget = GameObject.Find("PlayerObjectName").GetComponent(typeof(Transform)) as Transform;
more ▼

answered May 06 '12 at 07:49 PM

slgooding gravatar image

slgooding
31 2 2 4

Just want to say that this:

.GetComponent(typeof(Transform)) as Transform

is the same as

.transform
May 06 '12 at 07:54 PM Bunny83
(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:

x1091
x405
x243

asked: May 06 '12 at 07:01 PM

Seen: 362 times

Last Updated: May 06 '12 at 07:54 PM