我製作了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