// Update is called once per frame public virtual void FixedUpdate() { if (health.currentHealth <= 0) { explode.OnExplode(); GameObject manager = GameObject.FindGameObjectWithTag("Manager"); if (manager == null) { return; } GameManager gm = manager.GetComponent <GameManager>(); gm.AddToScore(10); } float verticalVel = Mathf.Sin(Time.fixedTime) * vertical * verticalMult; rb2.velocity = new Vector2(-maxSpeed * speedMultiplier, verticalVel); //Destoy enemies if they are offscreen Vector2 screenpos = Camera.main.WorldToScreenPoint(rb2.position); if (screenpos.x < -15f) { Destroy(gameObject); } }
void OnTriggerEnter2D(Collider2D target) { if (target.gameObject.tag == "Player") { if (collectSound) { Player.Instance.AudioPlayer.PlayOneShot(collectSound); } OnCollect(target.gameObject); if (Player.Instance.Health <= (100 - AddHP)) { Player.Instance.Health += AddHP; } else { Player.Instance.Health = 100; } Player.Score += AddScore; if (gameObject.tag == "WaterSplash") { ExplodeScript.OnExplode(); } else { Destroy(gameObject); } } }
void Update() { if (health.currentHealth <= 0) { Instantiate(_death, transform.position, Quaternion.identity); explode.OnExplode(); gameManager.setStopCount(true); gameOverScreen.SetUp(gameManager.getScore(), gameManager.getHighScore()); gameOverMusic.SetUp(); } // current vertical velocity var velY = body2D.velocity.y; var rotation = transform.rotation.z; // If the move button is pressed, apply force upwards if (controller.moving.y > 0) { if (velY < maxSpeed) { body2D.AddForce(new Vector2(0, increaseSpeedBy * 5)); } if (rotation <= maxRotation) { transform.Rotate(Vector3.forward * rotateBy); } else { transform.Rotate(Vector3.back * rotateBy); } } else { if (rotation >= -maxRotation) { transform.Rotate(Vector3.back * rotateBy); } else { transform.Rotate(Vector3.forward * rotateBy); } } if (_isInvincible) { _shield.enabled = true; } else { _shield.enabled = false; } }
void Update() { transform.position = new Vector2(transform.position.x + currentForwardSpeed, transform.position.y + (altitudeSpeed * controller.moving.y)); //rigidbody2D.velocity = new Vector2 (transform.localScale.x, 0) * currentForwardSpeed; //transform.position = new Vector2 ((transform.position.x + currentForwardSpeed) * Time.deltaTime, (transform.position.y + (altitudeSpeed * controller.moving.y)) * Time.deltaTime); Accelerate(); if (prevXPos >= transform.position.x) { print("destroyed" + destroyed); destroyed++; exploder.OnExplode(); } prevXPos = transform.position.x; }
void Update() { if (player == null) { return; } if (air > 0) { air -= Time.deltaTime * airBurnRate; slider.value = air / maxAir; } else { Explode script = player.GetComponent <Explode>(); script.OnExplode(); } }
void OnTriggerStay2D(Collider2D target) { if (target.gameObject.tag == "Player") { if (readyToAttack) { Explode explode = target.GetComponent <Explode>() as Explode; explode.OnExplode(); } else { animator.SetInteger("AnimState", 1); if (attackSound) { AudioSource.PlayClipAtPoint(attackSound, transform.position); } } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Enemy") { if (!_isInvincible) { health.takeDamage(25); } // destroy enemy too GameObject enemy = other.gameObject; Explode boom = enemy.GetComponent <Explode>(); boom.OnExplode(); } if (other.gameObject.tag == "EnemyProjectile") { if (!_isInvincible) { health.takeDamage(15); } } }