示例#1
0
    void OnCollisionEnter(Collision collision)
    {
        GamerController        gamerController  = GetGameController();
        List <CharacterObject> characterObjects = gamerController.GetAllCharacterObjects();

        //get contact point
        Vector3 collisionPosition = collision.contacts[0].point;

        for (int i = 0; i <= 1; ++i)
        {
            Vector3 characterPosition = characterObjects[i].charObject.transform.position;
            float   distance          = Vector3.Distance(collisionPosition, characterPosition);
            if (distance < impactDistance)
            {
                characterObjects[i].charActions.Damage();
                int health = (int)((1 - (distance / impactDistance)) * 20);
                gamerController.UpdateHealth(characterObjects[i], -health);
            }
        }

        GameObject exp = Instantiate(explosion, transform.position, transform.rotation);

        Destroy(gameObject);
        Destroy(exp, 2);
    }
示例#2
0
    // Trigger events - this basically collects th gun orb which allows the player get the power to use the gun
    private void OnTriggerEnter(Collider col)
    {
        GamerController mainGameController = GetGameController();
        CharacterObject currentPlayer      = mainGameController.GetCurrentCharacterProperties();

        if (col.name.StartsWith("FlareMobile"))
        {
            currentPlayer.WeaponAllowed = true;
            mainGameController.UpdateHealth(currentPlayer, 20f);
            Destroy(col.gameObject);
        }
    }