いいえ、私は一致を表すpreafabを作った。メインカメラに付属のスクリプトでその製(破壊されてきた私は15試合、unity 3d make prefabオブジェクトを破棄できない/ unclibable
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
public class LoadMatches : MonoBehaviour {
public GameObject match;
GameObject[] matchArray = new GameObject[15];
void Start() {
DrawMatches();
}
private void DrawMatches()
{
int y = 4;
int x = -4;
int n = 0;
for (int i = -4; i < 5; i += 2)
{
for (int j = x; j < y + 1; j += 2)
{
matchArray[n]=Instantiate(match, new Vector3(j, i, 0), Quaternion.identity) as GameObject;
matchArray[n].name= Convert.ToString(n);
n++;
}
y = y - 1;
x = x + 1;
}
}
}
を作って、私は、オブジェクトのオブジェクトをクリックすると、私はこの
を得ました)しかし、私はいくつかの行のオブジェクトをクリックすると、そのオブジェクトだけが他の行のmatcherは、ボタンが押されるまでundestroyable/unclickabeになっていなければならないことを破壊することができます。
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
public class DragDrop : MonoBehaviour {
float x;
float y;
public GameObject match;
private txtGameOver txtGO;
private void Awake()
{
txtGO = GameObject.FindObjectOfType<txtGameOver>();
}
private void Start()
{
match.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
}
void Update(){
x = Input.mousePosition.x;
y = Input.mousePosition.y;
}
void OnMouseDrag(){
transform.position = Camera.main.ScreenToWorldPoint(new Vector3(x,y,10.0f));
}
void OnMouseDown()
{
var boxes = GameObject.FindGameObjectsWithTag("Match");
SelectMatches(match);
if (boxes.Length == 1)
{
txtGO.GameOverText();
}
}
void SelectMatches (GameObject m)
{
int n;
n = Convert.ToInt32(m.name);
if (n>=0 && n<=4)
{
Destroy(m);
}
else if (n > 4 && n <= 8)
{
Destroy(m);
}
else if (n > 8 && n <= 11)
{
Destroy(m);
}
else if (n > 11 && n <= 13)
{
Destroy(m);
}
else if (n==14)
{
Destroy(m);
}
}
}
私の質問は、スクリプトでunclikable/undestroyableいくつかのオブジェクトを作った方法です。
興味深いaproach。私はその解決策を試みます。 –
この回答が有用な場合は、@IstarEnkiの矢印をクリックしてください。ありがとう – TheGinxx009
私は矢印を入れたが、私のreputaionは15以下であり、私はclikcが記録するmsgを得た。しかしThnks、私は考えを得た。今は私のスクリプトにこのソリューションを採用しようとしています。私はいくつかの問題を抱えています。なぜなら、異なる名前の0〜14のオブジェクトを15個メダルしているからです。今はそれらを手助けする方法を磨いています。 –