8
8

More than 5 years have passed since last update.

UnityのSerializeFieldは、簡単に外部ファイルを実行できて便利

Posted at

SerializeFieldを使えば外部から必要な処理を呼び出す事ができます。ちょっと、適切な例じゃないと思いますが
Cubeを動かすのに2つのスクリプトを用意して、片方にはアニメーションの実行文、もう片方には関数を呼び出して実行しています。

スクリーンショット 2014-09-07 23.23.15.png

スクリプトは、以下のような感じ。

スクリーンショット 2014-09-07 23.23.36.png

MovePattern
using UnityEngine;
using System.Collections;

public class MovePattern : MonoBehaviour {
    public float num=0;
    public GameObject gameobject;

    public void rote()
    {
        gameobject.transform.eulerAngles = new Vector3(num*5, num*5, 0);
    }
}

スクリーンショット 2014-09-07 23.23.45.png

using UnityEngine;
using System.Collections;

public class TestSerializeField : MonoBehaviour {
    [SerializeField]
    MovePattern movepattern;
    void Update () {
        movepattern.rote();
    }
}

SerializeFieldでこんな簡単に呼び出せます。

8
8
1

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
8
8