途中だけどごめんねー
この記事でできること
- 外部のスクリプトにある変数を取得できるようになる。
参考例
- Sceneにはplaneとcubeを設置して、それぞれにPublicの変数を設ける。
- planeオブジェクト
- testA.cs
- 変数intTestAは10
- cubeオブジェクト
- testB.cs
- 変数intTestBは20
testA.cs
using UnityEngine;
public class testA : MonoBehaviour
{
public int intTestA = 10;
}
testB.cs
using UnityEngine;
public class testB : MonoBehaviour
{
public int intTestB = 20;
testA script;
void Start()
{
script = GameObject.Find("Plane").GetComponent<testA>();
Debug.Log(script.intTestA);
}
}