私は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