我制作了2个脚本,并将其分配给2个立方体:“立方体”和“立方体1”。 通常,如果您单击多维数据集,它会设置一个值,以便当您单击多维数据集1时它会消失。 如果先点击立方体1,它不会工作。 这就是我试图做的,但它不起作用,我不明白为什么。为什么我的脚本统一不起作用
这里是我的脚本
立方体:
using UnityEngine;
using System.Collections;
public class script : MonoBehaviour
{
public int test = 0; // make the variable for the value
public void OnMouseDown() // when the user click
{
test = 1; //make the value of test 1
}
}
立方体1:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript1 : MonoBehaviour
{
public GameObject a; //make a gameobject
public script script; //make a variable where we put in the script
void OnMouseDown() // when the user click
{
script = a.GetComponent<script>(); // get script
if (script.test == 1) //test or the variable test in the other script is 1
{
Destroy(gameObject); // destroy the object
}
}
}
有人可以帮我吗?
你可以添加现在正在发生的事情吗?编辑:我对统一很陌生,但也许,如果你检查[GetComponent()](http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html)的文档,它会返回附加到您正在调用该函数的对象。所以...可能会做一些像cube.GetCompoment()? Idk,只是我的猜测。 – Meraj99