void InitPlatform() { platformBase pb = Instantiate(platformPrefab, startSpawn, Quaternion.identity).GetComponent <platformBase>(); pb.name = index.ToString(); pb.speed = Random.Range(0.7f, 0.9f); startSpawn.y -= spawnDelta; currentPlatformCount++; index++; // nextPlatform = pb.gameObject; }
void MakePlatforms() { if (currentPlatformCount < maxPlatforms) { platformBase pb = Instantiate(platformPrefab, startSpawn, Quaternion.identity).GetComponent <platformBase>(); pb.name = index.ToString(); pb.speed = Random.Range(0.7f, 0.9f); startSpawn.y -= spawnDelta; currentPlatformCount++; index++; } }
void OnCollisionEnter2D(Collision2D cols) { if (cols.collider.CompareTag("platform")) { if (levelScript.nextPlatform == null && levelScript.currentPCPlatform == null) { //gameover Destroy(gameObject); } else if (cols.transform.parent.name != levelScript.nextPlatform.name && levelScript.currentPCPlatform == null) { //gameover Destroy(gameObject); } else { if (currentplatform == null) { currentplatform = cols.transform.parent.GetComponent <platformBase> (); } if (strength >= currentplatform.hp) { //breakthrough if (transform.parent != null) { transform.SetParent(null); } if (currentplatform != null) { currentplatform = null; } levelScript.SetNextPlatform(); Destroy(cols.transform.parent.gameObject); thisRigidbody.AddForce(breakforce); levelScript.currentPlatformCount--; return; } levelScript.currentPCPlatform = cols.transform.parent.gameObject; currentplatform.TakeDmg(strength); cols.transform.position += new Vector3(0, 0.3f, 0); if (transform.parent == null) { transform.SetParent(cols.transform.parent); } } } }