Example #1
0
    private void OnCollisionEnter(Collision collision)
    {
        if (this.gameObject.tag == "shortEnemy" || this.gameObject.tag == "mediumEnemy")
        {
            if (collision.gameObject.tag == "bat")
            {
                //float force = 50;
                Vector3 force     = ovrScript.getSwingVelocity();
                Vector3 direction = collision.contacts[0].point - this.gameObject.transform.position;
                direction = -direction.normalized;
                this.gameObject.GetComponent <Rigidbody>().AddForce(direction.x * force.x, 0, direction.z * force.z, ForceMode.Impulse);
                hitWithBat = true;
                Debug.Log("hit by bat");
            }
            else if (collision.gameObject.tag == "Player")
            {
                Debug.Log("hit by " + collision.gameObject.tag);
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }

        else if (this.gameObject.tag == "tallEnemy")
        {
            if (collision.gameObject.tag == "Player")
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }
        else if (this.gameObject.tag == "platform")
        {
            isGrounded = true;
        }
    }