纳金网

标题: Unity3d教你如何同场景不同物体传值 [打印本页]

作者: 王者再临    时间: 2014-10-31 15:23
标题: Unity3d教你如何同场景不同物体传值
  1. using UnityEngine;  
  2.     using System.Collections;  

  3.     public class Score : MonoBehaviour {  
  4.         //Unity3d:www.unitymanual.com
  5.         public  int allScore=100;  

  6.         // Update is called once per frame  
  7.         void Update () {  
  8.             allScore = 100;  

  9.         }  
  10.     }  
复制代码
这个脚本放在cube上,我想调用这个allScore。
  1.     using UnityEngine;  
  2.     using System.Collections;  

  3.     public class text : MonoBehaviour {  

  4.         public GameObject Obj1;  

  5.         // Use this for initialization  
  6.         void Start () {  
  7.             Obj1 = GameObject.Find("Cube");  
  8.             Score script=Obj1.GetComponent<Score>();  
  9.             Debug.Log(script.allScore);   
  10.         }  

  11.         // Update is called once per frame  
  12.         void Update () {  

  13.         }  
  14.     }  
复制代码
就可以打印出allScore了。

      * 版权声明:转载时请以超链接形式标明文章原始出处和作者信息
      * 本文链接:http://www.unitymanual.com/7183.html

作者: HIDEOKOJIMA    时间: 2014-10-31 17:42
Thanks for sharing this one !
作者: cclove    时间: 2014-10-31 17:45
哈哈,高级。不同场景间怎么传值呢。。。




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5