- Home /
Question by
hyderox · May 06, 2012 at 07:01 PM ·
objectgetcomponenttarget
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?
Comment
I didn't downvote your question, but... this is a joke, right?
Answer by slgooding · May 06, 2012 at 07:49 PM
Under the Mob's script you can use the following (c#):
Transform PTarget = GameObject.Find("PlayerObjectName").GetComponent(typeof(Transform)) as Transform;
Just want to say that this:
.GetComponent(typeof(Transform)) as Transform
is the same as
.transform
Your answer
![](https://koobas.hobune.stream/wayback/20220613071151im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
target and look at random enemies 1 Answer
How to make an object to look at Raycast Hit Point? 1 Answer
How do I change Sprites (and manipulate the Sprite Object) in C#? 0 Answers
NullReferenceException: Object reference not set to an instance of an object ..... 1 Answer
GetComponent is not member of Object? 2 Answers