---
# System prepended metadata

title: Script 常用
tags: [Unity C# 好用寫法]

---

###### tags: `Unity C# 好用寫法`
[toc]

# Script 常用

# 抓不同script的變數

## 方法一

```csharp=
public GameObject variable_name;
GameObject.GetComponent<Script_Name>().variable_name;
```

## 方法二(效率較差)

**被讀取的script**
```csharp=
public static data_type variable_name;
```
**讀取的script**
```csharp=
script_name.variable;
```

# 腳本停用

```csharp=
GameObject.Find("Object_Name").GetComponent<Scrpit_Name>().enabled = true / False
```