script, , , OnTriggerEnter2D(), :
private Vector3 ballPosition;
public bool spawnNewBall;
void Start() {
spawnNewBall = true;
}
void OnTriggerEnter2D (Collider2D other) {
if (other.gameObject.tag == "Ball") {
if (spawnNewBall) {
other.GetComponent<>().spawnNewBall = false;
}
ballPosition = new Vector3 ((transform.position.x + other.transform.position.x) / 2, (transform.position.y + other.transform.position.y) / 2, 0.0f);
StartCoroutine ("RespawnBall");
}
}
IEnumerator RespawnBall () {
if (spawnNewBall) {
Instantiate (gameObject, ballPosition, Quaternion.identity);
}
Destroy (gameObject);
yield return null;
}
, :
public class TwoToOne : MonoBehaviour {
public bool doNothing;
void OnCollisionEnter (Collision col)
{
if (doNothing) return;
col.gameObject.GetComponent<TwoToOne>().doNothing = true;
Destroy(col.gameObject);
GameObject newCube = Instantiate(gameObject);
Destroy(gameObject);
}
}
script Unity.
, " "; , . Unity :
A, "" - . DestroyImmediate(col.gameObject) Unity.
B, "" script . col.gameObject.GetComponent<TwoToOne>().enabled = false Unity
C, "flag" ( ) - .
, Unity A B, C. B - , Unity5, C!