Example #1
0
 private void CancelAttack(LaserAttack laserAttack, bool cancelSound)
 {
     if (cancelSound)
     {
         this.musicController.CancelLaserAndThunder();
     }
     Object.Destroy(laserAttack.gameObject);
     this.rigidbody.bodyType = RigidbodyType2D.Dynamic;
     this.attacking          = false;
 }
Example #2
0
        private IEnumerator CAttack()
        {
            this.attacking          = true;
            this.rigidbody.velocity = Vector2.zero;
            this.rigidbody.bodyType = RigidbodyType2D.Static;

            var myPos    = this.transform.position;
            var mousePos = this.camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -this.camera.transform.position.z));

            mousePos.z = myPos.z;

            this.model.transform.LookAt(mousePos);
            this.model.transform.eulerAngles = new Vector3(0, this.model.transform.eulerAngles.y, this.model.transform.eulerAngles.z);

            yield return(new WaitForSeconds(this.laserSoundDelay));

            this.musicController.PlayLaser();
            yield return(new WaitForSeconds(this.laserPrepareTime - this.laserSoundDelay));

            GameObject  laserObj    = Object.Instantiate(this.laserPrefab, this.laserOrigin.position, Quaternion.identity);
            LaserAttack laserAttack = laserObj.GetComponent <LaserAttack>();

            laserAttack.transform.LookAt(mousePos);

            laserAttack.Buildup(this.laserBuildupTime);
            this.musicController.PlayThunder();

            for (float time = 0; time < this.laserBuildupTime; time += Time.deltaTime)
            {
                if (!this.attacking)
                {
                    this.CancelAttack(laserAttack, true);
                    yield break;
                }
                yield return(null);
            }

            laserAttack.SetLaserWidth(0.06f);
            laserAttack.Disappear(this.laserDisappearTime);

            for (float time = 0; time < this.laserDisappearTime; time += Time.deltaTime)
            {
                if (!this.attacking)
                {
                    this.CancelAttack(laserAttack, false);
                    yield break;
                }
                yield return(null);
            }

            Object.Destroy(laserAttack.gameObject);
            this.rigidbody.bodyType = RigidbodyType2D.Dynamic;
            this.attacking          = false;
        }