private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Enemy"))    //if player collides with enemy on their head(1.0f contact point) then kill enemy, otherwise hurt playerand remove one heart
     {                                                //when player runs out of herats start the No_Heart coroutine
         foreach (ContactPoint2D point in collision.contacts)
         {
             Debug.Log(point.normal); //kill enemy
             if (point.normal.y >= 0.9f)
             {
                 rb.velocity = Vector2.up * EnemyKillJump;
                 EnemyDeathEffect();
                 AddJump();
                 Destroy(collision.gameObject);
             }
             if (point.normal.x >= 0.8f) //damaj player
             {
                 playerHealth = playerHealth - 1;
                 shake.CamShake();
                 AudioSource.PlayClipAtPoint(PlayerDamage, transform.position);
                 print(playerHealth);
             }
             else if (point.normal.x <= -0.8f)
             {
                 playerHealth = playerHealth - 1;
                 shake.CamShake();
                 AudioSource.PlayClipAtPoint(PlayerDamage, transform.position);
                 print(playerHealth);
             }
         }
     }
 }
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player" && other.GetComponent <Health> () != null)
        {
            shake.CamShake();
            other.gameObject.GetComponent <Health> ().currentHealth -= 1f;

            if (other.gameObject.GetComponent <PlayerControl> () != null)
            {
                Instantiate(other.gameObject.GetComponent <PlayerControl> ().playerBloodParticles, transform.position, Quaternion.identity);
            }
            Destroy(gameObject);
        }

        if (other.GetComponent <Collider>().tag == "Respawn" && other.GetComponent <Collider>().tag != "Enemy")
        {
            Destroy(other.gameObject, 3f);
        }

        if (other.GetComponent <Collider>().tag == "Shield")
        {
            shake = GameObject.FindGameObjectWithTag("ScreenShake").GetComponent <ScreenShake> ();
            Destroy(this.gameObject);
            this.GetComponent <Rigidbody> ().AddExplosionForce(10f, transform.position, 10f);
        }
    }
Exemplo n.º 3
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Player"))
     {
         player.vida--;
         Debug.Log(player.vida);
         GameObject ef = Instantiate(efeitoInimigo, transform.position, Quaternion.identity);
         shake.CamShake();
         Destroy(ef, 2f);
         Destroy(gameObject);
     }
     if (other.CompareTag("Projetil"))
     {
         GameObject ef  = Instantiate(efeitoInimigo, transform.position, Quaternion.identity);
         GameObject efT = Instantiate(efeitoTiro, transform.position, Quaternion.identity);
         shake.CamShake();
         Destroy(ef, 2f);
         Destroy(efT, 2f);
         Destroy(other.gameObject);
         Destroy(gameObject);
     }
 }
Exemplo n.º 4
0
    void OnCollisionEnter(Collision other)
    {
        if (other.transform.tag == "Respawn")
        {
            blank = other.transform;
            shake.CamShake();
            Destroy(other.gameObject, 0.5f);

            other.gameObject.GetComponent <Rigidbody> ().AddExplosionForce(100f, other.transform.position, 100f, 100f, ForceMode.Impulse);

            if (other.gameObject.GetComponent <Rigidbody> () != null)
            {
                SpoilsSpawn(charges: 1);
            }
        }

        if (other.collider != null && this.tag == "ImpactType")
        {
            if (this.GetComponent <AudioSource> () != null)
            {
                this.GetComponent <AudioSource> ().Play();
            }
        }

        if (other.transform.tag == "Enemy")
        {
            blank = other.transform;
            shake.CamShake();
            FindObjectOfType <PlayerControl> ().gravity = 0f;

            if (other.gameObject.GetComponent <Rigidbody> () != null)
            {
                SpoilsSpawn(charges: 3);
                Instantiate(FindObjectOfType <PlayerControl> ().enemyBloodParticles, transform.position, Quaternion.identity);
                other.gameObject.GetComponent <Rigidbody> ().constraints = RigidbodyConstraints.None;
            }
            Destroy(other.gameObject, .2f);
        }
    }
Exemplo n.º 5
0
    private void FollowThePlayer()
    {
        if (m_Distance >= m_AttackRange)
        {
            m_bAttacked         = false;
            transform.position += transform.forward * m_MoveSpeed * Time.deltaTime;
            if (WaterLevel.m_WaterLevel < transform.position.y)
            {
                transform.position = new Vector3(transform.position.x, WaterLevel.m_WaterLevel, transform.position.z);
            }
        }
        else
        {
            if (!m_bAttacked)
            {
                m_bAttacked = true;

                //Get the spawn point from the player
                Transform spawnPoint = m_Target.Find("ElectricSpawnPoint").transform;

                //Spawn eletric particles infront of camera + screenshake
                GameObject bElectricParticle = (GameObject)Instantiate(m_electricParticle, spawnPoint.position, spawnPoint.rotation);
                GameObject bEelParticle      = (GameObject)Instantiate(m_electricParticle, transform.position, transform.rotation);

                //Player electric
                bElectricParticle.transform.parent = spawnPoint;
                bElectricParticle.GetComponent <ParticleSystem>().Play();
                //StartCoroutine(m_screenShake.Shake(.5f, .05f));
                m_screenShake.CamShake();
                m_anim.SetTrigger("attack");
                StartCoroutine(FlashUIOnce(m_screenFlash, m_screenFlash2));
                //Eel electric
                bEelParticle.GetComponent <ParticleSystem>().Play();

                GetComponent <AudioSource>().Play();

                Destroy(bEelParticle, 1.5f);
                Destroy(bElectricParticle, 2.0f);
            }
            //SpawnMore.SpawnMoreOfThisType(this.gameObject);
            //GameObject.FindGameObjectWithTag("SpawnMore").GetComponent<SpawnMore>().SpawnMoreOfThisType(this.gameObject);
        }

        transform.LookAt(m_Target.transform);
    }
Exemplo n.º 6
0
        // Destroys dead nodes from the NodeManager
        public void DestroyDeadNodes()
        {
            List <NumberNode> nodesToDestroy = new List <NumberNode>();

            // Loop over each node and mark them for destruction
            foreach (NumberNode node in NodeManager.GetNodes())
            {
                // If node is dead
                if (!node.alive)
                {
                    // Mark node eligible for destruction
                    nodesToDestroy.Add(node);


                    ParticlesList.Add(node.transform.position);
                    ScoreAdd.AddScore(10);
                    nodeDestroyedAudio.ShouldPlay = true;
                }
                else
                {
                    // If node is alive, but has reached the end of the gutter
                    if (node.pathFollower.distanceTravelled >= node.pathFollower.pathCreator.path.length)
                    {
                        // Mark node eligible for destruction
                        nodesToDestroy.Add(node);

                        screenShake.CamShake();
                        healthController.RemoveLife();
                        GameStateManager.SwitchToMoveBack();
                    }
                }
            }

            // Destroy nodes that are eligible for destruction
            // (Do this afterwards to not mess with the array during the foreach loop)
            foreach (NumberNode node in nodesToDestroy)
            {
                ScoreAdd.SetFurthestDistanceTravelled(node.pathFollower.distanceTravelled);
                NodeManager.RemoveNode(node);
                Destroy(node.gameObject);
            }
        }
Exemplo n.º 7
0
    void OnCollisionEnter(Collision other)
    {
        if (other.collider.tag == "Player")
        {
            shake.CamShake();

            currentHealthHolder = other.gameObject.GetComponent <Health> ().currentHealth;

            if (this.tag == "Enemy")
            {
                currentHealthHolder = currentHealthHolder - .5f;
            }

            if (this.tag == "Respawn")
            {
                currentHealthHolder = currentHealthHolder - 5f;
            }

            if (this.tag == "Finish")
            {
                other.gameObject.GetComponent <Health> ().Death();
            }

            if (this.GetComponent <AudioSource> () != null)
            {
                this.GetComponent <AudioSource> ().Play();
            }

            Destroy(this.gameObject, .1f);
        }

        if (other.collider.tag == "Respawn" && other.collider.tag != "Enemy")
        {
            other.gameObject.GetComponent <Rigidbody> ().AddExplosionForce(20f, other.transform.position, 20f);
            Destroy(other.gameObject, 3f);
            Destroy(this.gameObject, .1f);

            if (this.GetComponent <AudioSource> () != null)
            {
                this.GetComponent <AudioSource> ().Play();
            }
        }

        if (other.collider.tag == "Shield")
        {
            GetComponent <Rigidbody> ().AddExplosionForce(5f, other.transform.position, 5f);
            Destroy(this.gameObject, 2f);
            other.gameObject.SetActive(false);

            if (this.GetComponent <AudioSource> () != null)
            {
                this.GetComponent <AudioSource> ().Play();
            }
        }

        if (other.collider.tag != "Shield" && other.collider.tag != "Player" && other.collider.tag != "Respawn" && other.collider.tag != "Enemy")
        {
            if (this.GetComponent <AudioSource> () != null)
            {
                this.GetComponent <AudioSource> ().Play();
            }
            Destroy(this.gameObject, .1f);
        }
    }
Exemplo n.º 8
0
    void Update()
    {
        //log the hit point coordinates in console
        isShake = false;

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        mouseRay1 = GenerateRay();
            bool       isHit     = Physics.Raycast(mouseRay1.origin, mouseRay1.direction, out hit);
            if (isHit && hit.collider.gameObject.name == "Sphere")
            {
                gObj     = hit.transform.gameObject;
                objPlane = new Plane(Camera.main.transform.forward * -1, gObj.transform.position);

                //calculated mouse offsets
                Ray   mouseRay2 = Camera.main.ScreenPointToRay(Input.mousePosition);
                float rayDistance;
                objPlane.Raycast(mouseRay2, out rayDistance);
                mouseObject = gObj.transform.position - mouseRay2.GetPoint(rayDistance);
            }
        }
        else if (Input.GetMouseButton(0) && gObj)
        {
            Ray   mouseRay2 = Camera.main.ScreenPointToRay(Input.mousePosition);
            float rayDistance;
            if (objPlane.Raycast(mouseRay2, out rayDistance))
            {
                gObj.transform.position = mouseRay2.GetPoint(rayDistance) + mouseObject;
            }
        }
        else if (Input.GetMouseButtonUp(0) && gObj)
        {
            RaycastHit hit;
            Ray        mouseRay1 = GenerateRay();
            bool       isHit     = Physics.Raycast(mouseRay1.origin, mouseRay1.direction, out hit);
            Debug.LogError("Hit point at x:" + hit.point.x + ", y:" + hit.point.y + ", z:" + hit.point.z);
            float distanceToWantedAngle = calculateDistanceToWantedAngle(hit);
            int   screenShakeNumber     = getScreenShakeNumber(distanceToWantedAngle);


            gObj = null;
            if (isHit && hit.collider.gameObject.name == "WantedAngle")
            {
                Debug.LogError("Unlock");
                GameObject winScreen = GameObject.FindGameObjectWithTag("WinScreen");
                winScreen.GetComponent <MeshRenderer>().enabled = true;
                StartCoroutine(waitOneSecond(winScreen));

                GameObject timerUI = GameObject.Find("CountdownText");
                Destroy(timerUI);
            }
            else
            {
                Debug.LogError("Wanted Angle not find");

                //determine the magnitue of screen shake and carry the shake out
                if (!screenShakeNumber.Equals(0))
                {
                    screenShake.CamShake(screenShakeNumber);
                    isShake = true;
                    Debug.LogError("Not unlock");
                }
                else
                {
                    Debug.LogError("Odd distance appear");
                }
            }
        }
    }