コード例 #1
0
    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Player hit " + collision.gameObject.tag);

        if (collision.gameObject.tag == "Obstacle")
        {
            currentDealDamage = collision.gameObject.GetComponent <DealDamage>();
            if (currentDealDamage)
            {
                Debug.Log("Player takes Damage: " + currentDealDamage.damage);
                GameManager.instance.TakeDamage(currentDealDamage.damage);
                currentDealDamage.FadeRed();
            }
        }
    }
コード例 #2
0
        private void OnControllerColliderHit(ControllerColliderHit hit)
        {
            if (hit.gameObject.tag == "Obstacle")
            {
                currentObstacle = hit.gameObject.GetInstanceID();

                if (currentObstacle == prevObstacle)
                {
                    return;
                }

                currentDealDamage = hit.gameObject.GetComponent <DealDamage>();
                if (currentDealDamage)
                {
                    //Debug.Log("Player takes Damage: " + currentDealDamage.damage);
                    if (GameManager.instance != null)
                    {
                        GameManager.instance.TakeDamage(currentDealDamage.damage);
                    }

                    currentDealDamage.FadeRed();
                }
            }

            prevObstacle = hit.gameObject.GetInstanceID();

            Rigidbody body = hit.collider.attachedRigidbody;

            //dont move the rigidbody if the character is on top of it
            if (m_CollisionFlags == CollisionFlags.Below)
            {
                return;
            }

            if (body == null || body.isKinematic)
            {
                return;
            }

            body.AddForceAtPosition(m_CharacterController.velocity * 0.1f, hit.point, ForceMode.Impulse);
        }