Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GetComponent question

Discussion in 'Scripting' started by skuzzbag, Jun 4, 2011.

  1. skuzzbag

    skuzzbag

    Joined:
    May 23, 2011
    Posts:
    65
    Hi,

    In the following code from the script reference pages here I'm confused over where OtherScript is coming from. Can someone explain please?

    Thanks.

    Code (csharp):
    1.  
    2. function Start () {
    3. // By name
    4. var go = GameObject.Find("SomeGuy");
    5. go.GetComponent(OtherScript).DoSomething();
    6.  
    7. // By tag
    8. var player = GameObject.FindWithTag("Player");
    9. player.GetComponent(OtherScript).DoSomething();
    10. }
    11.