/// <summary> /// Processes trigger collisions with other game objects /// </summary> /// <param name="other">information about the other collider</param> void OnTriggerEnter2D(Collider2D other) { // if colliding with teddy bear, add score, destroy teddy bear, // and return self to pool if (other.gameObject.CompareTag("TeddyBear")) { unityEvents[EventName.PointsAddedEvent].Invoke(ConfigurationUtils.BearPoints); Instantiate(prefabExplosion, other.gameObject.transform.position, Quaternion.identity); Destroy(other.gameObject); Instantiate(prefabExplosion, transform.position, Quaternion.identity); FrenchFriesPool.ReturnFrenchFries(gameObject); } else if (other.gameObject.CompareTag("TeddyBearProjectile")) { // if colliding with teddy bear projectile, destroy projectile and // return self to pool Instantiate(prefabExplosion, other.gameObject.transform.position, Quaternion.identity); Destroy(other.gameObject); Instantiate(prefabExplosion, transform.position, Quaternion.identity); FrenchFriesPool.ReturnFrenchFries(gameObject); } }
/// <summary> /// Use this for initialization /// </summary> void Start() { EventManager.Initialize(); DifficultyUtils.Initialize(); ConfigurationUtils.Initialize(); FrenchFriesPool.Initialize(); }
/// <summary> /// Update is called once per frame /// </summary> void Update() { Vector3 position = transform.position; // get new horizontal position float horizontalInput = Input.GetAxis("Horizontal"); if (horizontalInput < 0) { position.x += horizontalInput * ConfigurationUtils.BurgerMoveUnitsPerSecond * Time.deltaTime; } else if (horizontalInput > 0) { position.x += horizontalInput * ConfigurationUtils.BurgerMoveUnitsPerSecond * Time.deltaTime; } // get new vertical position float verticalInput = Input.GetAxis("Vertical"); if (verticalInput < 0 || verticalInput > 0) { position.y += verticalInput * ConfigurationUtils.BurgerMoveUnitsPerSecond * Time.deltaTime; } // move and clamp in screen transform.position = position; ClampInScreen(); // reenable shooting on Fire1 axis release if (!canShoot && Input.GetAxisRaw("Fire1") == 0) { cooldownTimer.Stop(); canShoot = true; } // shoot french fries if (canShoot && Input.GetAxisRaw("Fire1") != 0) { cooldownTimer.Run(); canShoot = false; Vector3 frenchFriesPos = transform.position; frenchFriesPos.y += FrenchFriesPositionOffset; GameObject frenchFries = FrenchFriesPool.GetFrenchFries(); frenchFries.transform.position = frenchFriesPos; frenchFries.SetActive(true); frenchFries.GetComponent <FrenchFries>().StartMoving(); AudioManager.Play(AudioClipName.BurgerShot); } }
/// <summary> /// Called when the french fries become invisible /// </summary> void OnBecameInvisible() { // return to the pool FrenchFriesPool.ReturnFrenchFries(gameObject); }