using UnityEngine;
using System.Collections;
public class MyScript : MonoBehaviour {
public string myName = "myName";
public Vector3 pos;
public bool visible;
}
下面是附加在场景中的游戏对象上的主要代码:
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
public GameObject cube;
void Update() {
if(Input.GetKeyDown(KeyCode.Space)) {
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent<MyScript>();
if(Input.GetKeyDown(KeyCode.LeftShift)) {
var a = GameObject.Find("Cube");
print("cube name/visible: " +
/* here is the problem, how do i access the MyScript variables? */
a.myName + "/" + a.visible);
}