码迷,mamicode.com
首页 > 其他好文 > 详细

Unity 调用另一个脚本数据

时间:2014-07-31 16:21:16      阅读:591      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   数据   for   2014   

脚本1:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {
    // Use this for initialization
    void Start ()
    {
        ScriptB b = null;
        b = GameObject.Find ("Main Camera").GetComponent<ScriptB> ();
        Debug.Log ("ScriptB‘s num_b = " + b.num_b);
    }

    // Update is called once per frame
    void Update () {
    }
}

 

脚本2:

using UnityEngine;
using System.Collections;

public class ScriptB : MonoBehaviour {
    
    public int num_b = 5;

    // Use this for initialization
    void Start () {
    }
    
    // Update is called once per frame
    void Update () {
    }
}

 

  把脚本1脚本2都添加到Main Camera中,可以看到如下运行结果,脚本1成功调用了脚本2中的数据:

bubuko.com,布布扣

Unity 调用另一个脚本数据,布布扣,bubuko.com

Unity 调用另一个脚本数据

标签:style   blog   http   color   io   数据   for   2014   

原文地址:http://www.cnblogs.com/vitah/p/3880775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!