Exemplo n.º 1
0
 void OnCollisionEnter(Collision other)
 {
     if (attacking && other.gameObject.CompareTag("Enemy"))
     {
         other.gameObject.GetComponent <Death>().Hit(myAttack);
         playerTraits.EnemiesKilled++;
         playerTraits.AddHealth(2);
     }
     if (attacking && other.gameObject.CompareTag("Ally"))
     {
         other.gameObject.GetComponent <Death>().Hit(myAttack);
         playerTraits.AlliesKilled++;
         playerTraits.AddHealth(1);
     }
     if (attacking && other.gameObject.CompareTag("Bizarro"))
     {
         other.gameObject.GetComponent <Bizarro>().Hit(25, other.contacts[0].normal * 1000);
     }
 }
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.CompareTag("Food"))
     {
         foodEaten++;
         playerTraits.AddHealth(foodHealthValue);
         playerTraits.PlantsEaten++;
         GameObject eaten = (GameObject)Instantiate(eatenEffect, other.transform.position, Quaternion.identity);
         Destroy(eaten, 3f);
         Destroy(other.gameObject);
     }
 }
Exemplo n.º 3
0
 public void Hit(int damage, Vector3 normal, float bumpForce)
 {
     health -= damage;
     GetComponent <Rigidbody>().AddForce(-normal * bumpForce);
     GetComponent <Renderer>().material.color = Color.red;
     flashTimer.Go(flashTime);
     if (health <= 0)
     {
         playerTraits.AddHealth(healthValue);
         playerTraits.OthersEaten++;
         GetComponent <Renderer>().material.color = Color.red;
         Destroy(this.gameObject, 2f);
         GetComponent <Rigidbody>().useGravity       = false;
         GetComponent <Rigidbody>().detectCollisions = false;
         dying           = true;
         shrinkStartTime = Time.time;
         gameManager.EnemyFear++;
     }
 }
Exemplo n.º 4
0
    void Update()
    {
        if (gameManager.LevelStarted && !dazed)
        {
            moveX = Input.GetAxis("Horizontal");
            moveY = Input.GetAxis("Vertical");
            if (Input.GetButton("Fire1"))
            {
                clickVector = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
                if (bash && canBash)
                {
                    bashing = true;
                    if (gameManager.CurrentLevel >= 3)
                    {
                        playerKill.Attacking = true;
                    }
                    afterglow = true;
                    canBash   = false;
                    bashTimer.Go(bashTime);
                    bashReset.Go(bashResetTime);
                    GameObject myBashEffect = (GameObject)Instantiate(bashEffect, transform.position, Quaternion.Euler(0, -180, 180));
                    myBashEffect.transform.parent = transform;
                    Destroy(myBashEffect, 5f);
                }
                else if (dash && canDash)
                {
                    canDash = false;
                    dashTimer.Go(dashTime);
                    dashReset.Go(dashResetTime);
                    if (!canTeleport)
                    {
                        dashing = true;
                        if (gameManager.CurrentLevel >= 3)
                        {
                            playerKill.Attacking = true;
                        }
                        GameObject myDashEffect = (GameObject)Instantiate(dashEffect, transform.position, Quaternion.Euler(0, 180, 180));
                        myDashEffect.transform.parent = transform;
                        Destroy(myDashEffect, 5f);
                    }
                    else
                    {
                        Vector3 newPos            = transform.position;
                        float   teleportMagnitude = clickVector.magnitude;
                        if (teleportMagnitude != 0)
                        {
                            if (gameManager.CurrentLevel == 4)
                            {
                                GetComponent <PlayerWin>().TeleportBros(transform.position);
                            }
                            GameObject startTeleport = (GameObject)Instantiate(dashEffect, transform.position, Quaternion.Euler(0, 0, 180));
                            Destroy(startTeleport, 1f);
                            if (Vector3.Distance(transform.position, clickVector) >= teleportDistance)
                            {
                                //clickVector = Vector3.Normalize(clickVector);
                                newPos.x += clickVector.x * teleportDistance / teleportMagnitude;
                                newPos.y += clickVector.y * teleportDistance / teleportMagnitude;
                            }
                            else
                            {
                                newPos = clickVector;
                            }
                            transform.position = newPos;
                            GameObject endTeleport = (GameObject)Instantiate(endTeleportEffect, transform.position, Quaternion.Euler(0, 180, 180));
                            Destroy(endTeleport, 5f);

                            Collider[] colliders = Physics.OverlapSphere(transform.position, telefragRadius);
                            foreach (Collider c in colliders)
                            {
                                if (c.gameObject.CompareTag("Enemy"))
                                {
                                    playerTraits.EnemiesKilled++;
                                    playerTraits.AddHealth(2);
                                    c.GetComponent <Death>().Hit(2);
                                }
                                else if (c.gameObject.CompareTag("Ally"))
                                {
                                    playerTraits.AlliesKilled++;
                                    playerTraits.AddHealth(1);
                                    c.GetComponent <Death>().Hit(2);
                                }
                            }
                        }
                    }
                }
            }
            if (bashing)
            {
                Bash();
            }
            else if (dashing)
            {
                Dash();
            }
        }
        if (bumpingGigantor)
        {
            BumpGigantor();
        }
    }