// Use this for initialization void Start() { this.koopaScript = this.transform.parent.GetComponent<KoopaScript>(); this.player = GameObject.FindWithTag("Player"); this.playerScript = this.player.GetComponent<PlayerScript>(); this.playerRb = this.player.GetComponent<Rigidbody2D>(); }
void OnTriggerEnter2D(Collider2D c) { if (c.gameObject.name.StartsWith("koopa")) { KoopaScript koopa = c.gameObject.GetComponent <KoopaScript> (); if (koopa.fly) { koopa.flySpeed = -koopa.flySpeed; } } }
void OnTriggerEnter2D(Collider2D c) { if (c.gameObject.name.StartsWith("koopa")) { KoopaScript koopa = c.gameObject.GetComponent <KoopaScript> (); if (koopa.status == KoopaState.Run) { koopa.currentSpeed = -koopa.currentSpeed; } } }
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Barrier") { isBarrier = true; } if (isUnKill && (coll.gameObject.tag == "Enemy" || coll.gameObject.tag == "lacitu")) { Collider2D cd1 = coll.gameObject.GetComponent <CapsuleCollider2D> (); Rigidbody2D rigidbody2D = coll.gameObject.GetComponent <Rigidbody2D> (); SpriteRenderer sp1 = coll.gameObject.GetComponent <SpriteRenderer> (); sp1.sortingLayerName = "FrontLayer"; sp1.sortingOrder = 10; sp1.flipY = true; coll.transform.position = new Vector2(coll.transform.position.x, coll.transform.position.y + 0.5f); cd1.enabled = false; rigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionX; if (coll.gameObject.name.StartsWith("koopa")) { KoopaScript ks = coll.gameObject.GetComponent <KoopaScript> (); ks.status = KoopaState.Stand; ks.fly = false; ks.jump = false; Rigidbody2D rb2D = coll.gameObject.GetComponent <Rigidbody2D> (); rb2D.gravityScale = 1; } Destroy(coll.gameObject, 3f); Vector2 position = new Vector2(coll.transform.position.x, coll.transform.position.y + 2f); int scoreInt = 0; if (coll.gameObject.name.StartsWith("goomba")) { scoreInt = 100; } else { scoreInt = 200; } showScore(position, scoreInt); SoundEffectsHelper.Instance.Make_fireball_kill_Sound(); } }
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.name == "Player") { Rigidbody2D player_rb = coll.gameObject.GetComponent <Rigidbody2D> (); if (move && player_rb.velocity.y >= 0) { coll.gameObject.GetComponent <PlayerScript> ().isGameOver = true; } else { float reboundForce = coll.gameObject.GetComponent <PlayerScript> ().jumpForce / 2; player_rb.AddForce(Vector2.up * reboundForce, ForceMode2D.Impulse); Active = true; if (rb.velocity.x != 0) { currentSpeed = Mathf.Sign(rb.velocity.x) * -speed; } Vector2 position = new Vector2(coll.transform.position.x, coll.transform.position.y + 2f); showScore(position, 500); SoundEffectsHelper.Instance.Make_koopa_touch_Sound(); } } else if (isKiller && coll.gameObject.tag == "Enemy") { Vector2 position = new Vector2(coll.transform.position.x, coll.transform.position.y + 2f); int scoreInt = 0; if (coll.gameObject.name.StartsWith("goomba")) { scoreInt = 100; } else { scoreInt = 200; } showScore(position, scoreInt); SoundEffectsHelper.Instance.Make_fireball_kill_Sound(); Collider2D cd1 = coll.gameObject.GetComponent <CapsuleCollider2D> (); Rigidbody2D rigidbody2D = coll.gameObject.GetComponent <Rigidbody2D> (); SpriteRenderer sp1 = coll.gameObject.GetComponent <SpriteRenderer> (); sp1.sortingLayerName = "FrontLayer"; sp1.sortingOrder = 10; sp1.flipY = true; coll.transform.position = new Vector2(coll.transform.position.x, coll.transform.position.y + 0.5f); cd1.enabled = false; rigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionX; if (coll.gameObject.name.StartsWith("koopa")) { KoopaScript ks = coll.gameObject.GetComponent <KoopaScript> (); ks.status = KoopaState.Stand; ks.fly = false; ks.jump = false; Rigidbody2D rb2D = coll.gameObject.GetComponent <Rigidbody2D> (); rb2D.gravityScale = 1; } Destroy(coll.gameObject, 3f); } else if (coll.gameObject.tag == "Barrier" || coll.gameObject.tag == "Enemy") { currentSpeed = -currentSpeed; sr.flipX = !sr.flipX; } if (coll.gameObject.tag == "Barrier" && status == BuzzyState.Stand && move) { SoundEffectsHelper.Instance.Make_koopa_bump_Sound(); } }
void OnCollisionEnter2D(Collision2D coll) { isRebound = true; if (coll.gameObject.tag.Equals("Barrier") || coll.gameObject.tag.Equals("Enemy")) { cd.enabled = false; an.SetTrigger("stop"); rb.constraints = RigidbodyConstraints2D.FreezePosition; Destroy(gameObject, 0.2f); if (coll.gameObject.tag.Equals("Barrier")) { SoundEffectsHelper.Instance.Make_fireball_bang_Sound(); } else { SoundEffectsHelper.Instance.Make_fireball_kill_Sound(); } } if (coll.gameObject.tag.Equals("piranha")) { cd.enabled = false; an.SetTrigger("stop"); rb.constraints = RigidbodyConstraints2D.FreezePosition; SoundEffectsHelper.Instance.Make_fireball_kill_Sound(); Vector2 position = new Vector2(coll.transform.position.x, coll.transform.position.y + 2f); Destroy(coll.gameObject, 0.2f); Destroy(gameObject, 0.2f); showScore(position, 200); } if (coll.gameObject.tag.Equals("Enemy") && !coll.gameObject.name.StartsWith("buzzy")) { Collider2D cd1 = coll.gameObject.GetComponent <CapsuleCollider2D> (); Rigidbody2D rigidbody2D = coll.gameObject.GetComponent <Rigidbody2D> (); SpriteRenderer sp1 = coll.gameObject.GetComponent <SpriteRenderer> (); sp1.sortingLayerName = "FrontLayer"; sp1.sortingOrder = 10; sp1.flipY = true; coll.transform.position = new Vector2(coll.transform.position.x, coll.transform.position.y + 0.5f); cd1.enabled = false; rigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionX; if (coll.gameObject.name.StartsWith("koopa")) { KoopaScript ks = coll.gameObject.GetComponent <KoopaScript> (); ks.status = KoopaState.Stand; ks.fly = false; ks.jump = false; Rigidbody2D rb2D = coll.gameObject.GetComponent <Rigidbody2D> (); rb2D.gravityScale = 1; } Destroy(coll.gameObject, 3f); Vector2 position = new Vector2(coll.transform.position.x, coll.transform.position.y + 2f); int scoreInt = 0; if (coll.gameObject.name.StartsWith("goomba")) { scoreInt = 100; } else { scoreInt = 200; } showScore(position, scoreInt); } }