同一个场景在不同的物体之间进行传值,就像,在cube上有一个得分的脚本,我Main Camera上一个脚本需要用到cube上的得分。
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public int allScore=100;
// Update is called once per frame
void Update () {
allScore = 100;
}
}
这个脚本放在cube上,我想调用这个allScore。
using UnityEngine;
using System.Collections;
public class text : MonoBehaviour {
public GameObject Obj1;
// Use this for initialization
void Start () {
Obj1 = GameObject.Find("Cube");
Score script=Obj1.GetComponent<Score>();
Debug.Log(script.allScore);
}
// Update is called once per frame
void Update () {
}
}
这样就可以打印出allScore了。很简单但是很实用。
分享到:
相关推荐
高通AR 最新版 vuforia-unity-6-2-10 vuforia-unity-6-2-10
vuforia-unity-6-0-112.unitypackage
Unity日志输出插件,在手机和pc上均有用,能很清晰的看到日志打印,非常好用。 使用这个工具,你可以很容易地在游戏内部检查你的编辑器控制台日志!在移动端同样有效! 支持unity2017.4.29 or 更高版本
vuforia-samples-advanced-android-ios-unity-4-2-3.zip官网下载太慢了,放在网盘方便大家下载
第一人称射击游戏----FPSGame.zip------------------------unity4.3.4f1----------源代码 第一人称射击游戏----FPSGame.zip------------------------unity4.3.4f1----------源代码
Unity 免ADB真机日志查看插件分享Unity Logs Viewe。详情参看https://blog.csdn.net/wuming2016/article/details/90609787
vuforia-unity-android-modeltargetstest-10-5-5
unity-webview-integration-master unity-webview-integration-master unity-webview-integration-master
Unity和C#-游戏开发-官方超好画质的射击游戏源码+源代码工程
spine骨骼动画导入unity插件
这是一个原生的Unity插件,它将Apple的ARKit SDK的功能暴露 给兼容iOS设备的Unity项目。包括ARKit功能,如世界跟踪,直通相机渲染,水平和垂直平面检测和更新,面部跟踪(需要iPhone X),图像锚点,点云提取,光...
Unity-UI-Extensions,总有一款效果是你想要的!
unity spain 3.8 2021-11-10
vuforia-samples-core-unity-6-2-6 These samples show how to build apps using the following core features of Vuforia. Image Targets VuMark Object Recognition Cylinder Targets Multi Targets User ...
spine-unity-3.8-2021-01-08.unitypackage
为了速度慢下载失败或者无法下载的人提供,这是最新的vuforia unity sdk 6.2.10
Unity真机调试编辑器(Unity-Logs-Viewer-master),兼容iOS和Andriod系统边玩游戏面板显示Debug信息,非常方便;
UnitySetup-Android-Support-for-Editor-5.3.5f1UnitySetup-Android-Support-for-Editor-5.3.5f1UnitySetup-Android-Support-for-Editor-5.3.5f1UnitySetup-Android-Support-for-Editor-5.3.5f1
vuforia-unity-6-0-117.unitypackage 链接地址: https://developer.vuforia.com/downloads/sdk#downloadModal 有时候下载速度比较忙,所以上传一份