LoginSignup
0
0

More than 3 years have passed since last update.

外部スクリプトの変数を取得する方法

Last updated at Posted at 2020-11-29

途中だけどごめんねー

この記事でできること

  • 外部のスクリプトにある変数を取得できるようになる。

参考例

  • Sceneにはplaneとcubeを設置して、それぞれにPublicの変数を設ける。

a03.png

  • planeオブジェクト
    • testA.cs
    • 変数intTestAは10

a01.png

  • cubeオブジェクト
    • testB.cs
    • 変数intTestBは20

a02.png

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);
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0