---
title: "GetComponent"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/getcomponent?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting-old.md?language=en"
unit_title: "Beginner Scripting"
unit_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting?language=en"
standalone_markdown_url: "https://learn.unity.com/tutorial/getcomponent.md?language=en"
previous_title: "Detecting Mouse Clicks"
previous_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/onmousedown?language=en"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/onmousedown.md?language=en"
next_title: "Time"
next_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/delta-time?language=en"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/delta-time.md?language=en"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/getcomponent.md?language=en&version=4.x"
last_updated: "2026-08-04T14:22:29.000Z"
---

# GetComponent

Learn to use the GetComponent function to access and work with properties on other scripts and components in your project.

How to use the GetComponent function to address properties of other scripts or components.

This tutorial is included in the [Beginner Scripting project](https://learn.unity.com/project/beginner-gameplay-scripting).

Previous: [OnMouseDown](https://learn.unity.com/tutorial/onmousedown?projectId=5c8920b4edbc2a113b6bc26a)

Next: [Delta Time](https://learn.unity.com/tutorial/delta-time?projectId=5c8920b4edbc2a113b6bc26a)

## 1. GetComponent

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/b737678b-9a57-41f6-8f47-0f03a6d58399_U_Beginner_18_GetComponent.mp4)

## **UsingOtherComponents**

```csharp
using UnityEngine;
using System.Collections;

public class UsingOtherComponents : MonoBehaviour
{
    public GameObject otherGameObject;
    
    
    private AnotherScript anotherScript;
    private YetAnotherScript yetAnotherScript;
    private BoxCollider boxCol;
    
    
    void Awake ()
    {
        anotherScript = GetComponent<AnotherScript>();
        yetAnotherScript = otherGameObject.GetComponent<YetAnotherScript>();
        boxCol = otherGameObject.GetComponent<BoxCollider>();
    }
    
    
    void Start ()
    {
        boxCol.size = new Vector3(3,3,3);
        Debug.Log("The player's score is " + anotherScript.playerScore);
        Debug.Log("The player has died " + yetAnotherScript.numberOfPlayerDeaths + " times");
    }
}
```

## **AnotherScript**

```csharp
using UnityEngine;
using System.Collections;

public class AnotherScript : MonoBehaviour
{
    public int playerScore = 9001;
}
```

## **YetAnotherScript**

```csharp
using UnityEngine;
using System.Collections;

public class YetAnotherScript : MonoBehaviour
{
    public int numberOfPlayerDeaths = 3;
}
```
