LoginSignup
0
1

More than 5 years have passed since last update.

Unity2D ~自分以外のオブジェクトのコンポーネントを操作~

Posted at

はじめに

自分のオブジェクトから他のオブジェクトのコンポーネントいじりたい時ありますよね?
そんな時の処理です

playerからPassFloorへの操作

playerオブジェクトのスクリプトからPassFloorのTransformを動かす場合。

playerオブジェクトにスクリプトで読み込ませる。

Transform floor;

    void Start () {
        //コンポーネント読み込み
        floor = GameObject.Find("PassFloor").GetComponent<Transform>();
    }

こんな感じでsceneの中のオブジェクト名を指定してあげます。
あとは自分のコンポーネントと同じ感じでおk

初期から居るやつはFind()に名前入れてStart()で読み込ませたら良いけど途中で自動生成するやつとかはちょっと考えてやらないとね
メインループに入れると最高に重くなりそうです

0
1
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
1