示例#1
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            if (timing <= 0)
            {
                //Removes a shell from the crab
                for (int i = 0; i < shellLossWorth; i++)
                {
                    if (movement.shellCount > 0)
                    {
                        movement.spawnLooseShell();
                        movement.Lose_Shell();
                    }
                }
                timing = timer;
            }

            //repulses the player from the hazard
            Vector2 repulsionDirection = -(transform.position - movement.transform.position);
            Vector2 repulsionForce     = repulsionDirection * forceConstant;
            player.transform.GetComponent <Rigidbody2D>().AddForce(repulsionForce * 2);
            Debug.Log(repulsionForce);
        }
    }