예제 #1
0
 void Shooting()
 {
     if (canShoot)
     {
         sound.Play();
         RaycastHit2D hit = Physics2D.Raycast(target, Vector3.forward);
         Debug.Log(hit.collider);
         Debug.DrawRay(target, Vector3.forward, Color.yellow, 2);
         if (hit.collider != null)
         {
             //if a button is being shot
             if (hit.collider.GetComponent <CommonButton>() != null)
             {
                 hit.collider.GetComponent <CommonButton>().PressButton();
             }
             else if (hit.collider.tag == "Player")
             {
                 var controller = (ShootingSceneController)FindObjectOfType(typeof(ShootingSceneController));
                 controller.AttackPlayer();
             }
             else if (hit.collider.GetComponent <BulletScript>() != null)
             {
                 Destroy(hit.collider.gameObject);
                 scoreScript.AddPoints(50);
             }
             else if (hit.collider.GetComponent <ShootableObject>() != null)
             {
                 hit.collider.GetComponent <ShootableObject>().OnShoot();
                 scoreScript.AddPoints(75);
             }
             else if (hit.collider.GetComponent <Boss>() != null ||
                      hit.collider.GetComponent <Fireplace>() != null ||
                      hit.collider.GetComponent <VeloxScript>() != null ||
                      hit.collider.GetComponent <PortelloneScript>() != null)
             {
             }
             else
             {
                 Destroy(hit.collider.gameObject);
                 scoreScript.AddPoints(100);
             }
         }
         else
         {
             canShoot = false;
             //Debug.Log(canShoot);
             StartCoroutine(ReloadTimer());
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Create a line renderer and raycast for the laser shooting mechanic, during which the player cannot move.
 /// </summary>
 /// <returns>The coroutine.</returns>
 private IEnumerator LaserCoroutine()
 {
     canMove = false;
     while (Input.GetKey(KeyCode.Space))
     {
         Ray        ray = new Ray(gameObject.transform.position, new Vector3(0, 0, 1));
         RaycastHit hit;
         if (Physics.SphereCast(ray, 1.0f, out hit))
         {
             if (hit.collider.gameObject.CompareTag("Virus"))
             {
                 Destroy(hit.collider.gameObject);
                 ScoreScript.AddPoints();
                 GameObject.FindGameObjectWithTag("VirusDeath").GetComponent <AudioSource>().Play();
             }
             if (hit.collider.gameObject.CompareTag("RedBloodCell"))
             {
                 LoseLife();
                 Destroy(hit.collider.gameObject);
                 GameObject.FindGameObjectWithTag("RedCellDeath").GetComponent <AudioSource>().Play();
             }
         }
         laserLineRenderer.SetPosition(0, gameObject.transform.position);
         laserLineRenderer.SetPosition(1, gameObject.transform.position + new Vector3(0, 0, 60));
         laserLineRenderer.startWidth = 1f;
         laserLineRenderer.endWidth   = 1f;
         laserLineRenderer.enabled    = true;
         yield return(null);
     }
     laserLineRenderer.enabled = false;
     canMove = true;
 }
예제 #3
0
 private void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag.Equals("Player"))
     {
         ScoreScript.AddPoints(pointValue);
         Destroy(gameObject);
     }
 }
예제 #4
0
 private void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag.Equals("Player") && Input.GetButtonDown("Attack"))
     {
         ScoreScript.AddPoints(pointValue);
         Destroy(gameObject);
     }
 }
예제 #5
0
    private IEnumerator LaserCoroutine()
    {
        CanMove = false;
        while (Input.GetKey(KeyCode.Space))
        {
            Ray        ray = new Ray(gameObject.transform.position, new Vector3(0, 0, 1));
            RaycastHit hit;
            if (Physics.SphereCast(ray, 1.0f, out hit))
            {
                if (hit.collider.gameObject.CompareTag("Virus"))
                {
                    Destroy(hit.collider.gameObject);
                    ScoreScript.AddPoints();
                }
                if (hit.collider.gameObject.CompareTag("RedBloodCell"))
                {
                    GameObject stamSlider = GameObject.FindGameObjectWithTag("Stamina");
                    GameObject background = GameObject.FindGameObjectWithTag("Background");
                    Vector3    scale      = stamSlider.transform.localScale;

                    Vector3 bgscale = stamSlider.transform.localScale;
                    bgscale = background.transform.localScale;
                    float bgrelativeScale = (float)10 / (float)10;
                    scale.x = bgrelativeScale;
                    background.transform.localScale = scale;

                    Projectile.currentDeath++;
                    Destroy(hit.collider.gameObject);
//					Debug.Log (Projectile.currentDeath);
                    if (Projectile.currentDeath == 10)
                    {
                        SceneManager.LoadScene("MainMenu");                          // you die, game over
                    }
                    else
                    {
                        scale = stamSlider.transform.localScale;
                        float relativeScale = (float)Projectile.currentDeath / (float)10;
                        scale.x = relativeScale;
                        stamSlider.transform.localScale = scale;
                    }
                }
            }

            LaserLineRenderer.SetPosition(0, gameObject.transform.position);
            LaserLineRenderer.SetPosition(1, gameObject.transform.position + new Vector3(0, 0, 60));
            LaserLineRenderer.startWidth = 1f;
            LaserLineRenderer.endWidth   = 1f;
            LaserLineRenderer.enabled    = true;

            // make player not able to move
            yield return(null);
        }
        LaserLineRenderer.enabled = false;
        CanMove = true;
    }
예제 #6
0
    IEnumerator CountToDie(int seconds, Collision other)
    {
        yield return(new WaitForSeconds(seconds));

        if (other != null)
        {
            ScoreScript.AddPoints();
            Destroy(other.gameObject);
            Destroy(gameObject);
        }
    }
예제 #7
0
 /// <summary>
 /// Raises the collision enter event.
 /// </summary>
 /// <param name="other">Other.</param>
 void OnCollisionEnter(Collision other)
 {
     if (other.collider.CompareTag("Virus"))
     {
         GameObject.FindGameObjectWithTag("VirusDeath").GetComponent <AudioSource>().Play();
         ScoreScript.AddPoints();
     }
     else if (other.collider.CompareTag("RedBloodCell"))
     {
         GameObject.FindGameObjectWithTag("RedCellDeath").GetComponent <AudioSource>().Play();
         GameObject.FindObjectOfType <Player> ().GetComponent <Player> ().LoseLife();
     }
     Destroy(other.gameObject);
     Destroy(gameObject);
 }
    /// <summary>
    /// Raises the collision enter event.
    /// </summary>
    /// <param name="other">Other.</param>
    void OnCollisionEnter(Collision other)
    {
        int max = 10;

        if (other.gameObject.CompareTag("Hit"))
        {
            Debug.Log("Already hit");
            return;
        }

        StartCoroutine(CountToDie(1, other));

        if (other.collider.CompareTag("Virus"))
        {
            GameObject.FindGameObjectWithTag("VirusDeath").GetComponent <AudioSource>().Play();
            ScoreScript.AddPoints();
        }
        else if (other.collider.CompareTag("RedBloodCell"))
        {
            GameObject stamSlider = GameObject.FindGameObjectWithTag("Stamina");
            GameObject background = GameObject.FindGameObjectWithTag("Background");
            Vector3    scale      = stamSlider.transform.localScale;

            Vector3 bgscale = stamSlider.transform.localScale;
            bgscale = background.transform.localScale;
            float bgrelativeScale = (float)10 / (float)max;
            scale.x = bgrelativeScale;
            background.transform.localScale = scale;

            currentDeath++;

            //			Debug.Log (currentDeath);

            if (currentDeath == 10 && ScoreScript.score <= 120)
            {
                SceneManager.LoadScene("BronzeMedal");                  // you die, game over
            }
            else
            {
                scale = stamSlider.transform.localScale;
                float relativeScale = (float)currentDeath / (float)max;
                scale.x = relativeScale;
                stamSlider.transform.localScale = scale;
            }
        }
        other.gameObject.tag = "Hit";
    }