private void OnCollisionEnter2D(Collision2D collision) { GameObject lifeobj = GameObject.Find("Canvas"); scorecontroller lifescript = lifeobj.GetComponent <scorecontroller>(); GameObject shipobj = GameObject.Find("Canvas"); moveship shipscript = shipobj.GetComponent <moveship>(); if (collision.gameObject.tag == "asteroid") { shipscript.ship.velocity = Vector3.zero; shipscript.ship.angularVelocity = 0; shipscript.shipobject.transform.position = new Vector3(0, 0, 0); Destroy(collision.gameObject); lifescript.lives -= 1; } if (collision.gameObject.tag == "powerup") { shipscript.ship.angularVelocity = 0; } if (collision.gameObject.tag == "comet") { shipscript.ship.velocity = Vector3.zero; shipscript.ship.angularVelocity = 0; shipscript.shipobject.transform.position = new Vector3(0, 0, 0); Destroy(collision.gameObject); lifescript.lives -= 1; } }
// Update is called once per frame void Update() { scorecontroller scorescript = GetComponent <scorecontroller>(); /* bullet = GameObject.Find("bullet"); * * bullet.transform.Translate(Vector3.forward * Time.deltaTime); */ }
private void OnCollisionEnter2D(Collision2D collision) { GameObject scoreobj = GameObject.Find("Canvas"); scorecontroller scorescript = scoreobj.GetComponent <scorecontroller>(); /* GameObject bullets = GameObject.Find("ship"); * moveship shipscript = bullets.GetComponent<moveship>(); * * GameObject explode = GameObject.Find("explosion"); * GameObject oneexplode = Instantiate(explode); * oneexplode.transform.position = shipscript.bulletprefab.transform.position; */ if (collision.gameObject.tag == "asteroid") { Destroy(this.gameObject); Destroy(collision.gameObject); scorescript.score += 10; /* ParticleSystem explosion = oneexplode.GetComponent<ParticleSystem>(); * explosion.Play(); */ } if (collision.gameObject.tag == "comet") { Destroy(this.gameObject); Destroy(collision.gameObject); scorescript.score += 30; /* ParticleSystem explosion = oneexplode.GetComponent<ParticleSystem>(); * explosion.Play(); */ } if (collision.gameObject.tag == "edge") { Destroy(this.gameObject); } }