Ejemplo n.º 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.tag != "PickUp")
        {
            if (collision.collider.tag == "FallingObject" && collision.collider.gameObject != fallenObject)
            {
                ObjectThatShouldFall fallingObject = collision.collider.gameObject.GetComponent <ObjectThatShouldFall>();
                if (!fallingObject.isOnGround)
                {
                    GameObject  pickUpObject          = collision.collider.gameObject;
                    Rigidbody2D pickUpObjectRigidBody = pickUpObject.GetComponent <Rigidbody2D>();

                    float fallingSpeed = pickUpObjectRigidBody.velocity.x;
                    float weight       = pickUpObjectRigidBody.mass;
                    float gravity      = pickUpObjectRigidBody.gravityScale;

                    if (fallingSpeed > minFallingSpeedDetection)
                    {
                        float lostHealth = fallingSpeed * weight * gravity;
                        lostHealth = Mathf.Floor(lostHealth);

                        float   health       = healthManager.GetHealth();
                        Vector3 healthToLose = new Vector3(lostHealth / 10, 0.0f, 0.0f);

                        healthManager.LoseHealth(healthToLose);

                        fallenObject = collision.collider.gameObject;

                        Debug.Log(fallingSpeed + " " + weight + " " + gravity);
                        Debug.Break();
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    //Add oncollisionenter2d or ontriggerenter2d here to set IsBurning to true!//
    //F**k me sideways, it doesn't call oncollisionenter2d.
    // void oncollisionenter2d(Collider2D Collision){
    //  if (Collision.gameObject.tag == "Fireball"){
    //      IsBurning = true;
    //  }
    //  Debug.Log("1");
    // }

    /////////////////////////////////////////////////////////////////////////////

    void Update()
    {
        if (IsBurning == true)
        {
            if (!playSound)
            {
                //  AudioSource.PlayClipAtPoint(burnSound, transform.position);
                playSound = true;
            }


            Counter += 1;
            if (burningObject == null && Counter < 300)
            {
                float heightOfRopePiece = gameObject.GetComponent <Renderer>().bounds.size.y;
                float bottomOfRopePiece = transform.position.y + (heightOfRopePiece / 2);

                burningObject = Instantiate(fire, new Vector3(transform.position.x, bottomOfRopePiece, transform.position.z), Quaternion.identity);
                burningObject.transform.parent     = transform;
                burningObject.transform.rotation   = Quaternion.Euler(0.0f, 0.0f, 180.0f);
                burningObject.transform.localScale = new Vector3(5.0f, 5.0f, 1.0f);
            }

            if (HasDone == false)
            {
                //Add any executable code that you want to activate once, before waiting here!//

                playSound = false;

                ////////////////////////////////////////////////////////////////////////////////

                HasDone = true;
            }
            if (Counter == 150)
            {
                //If x != null is for error handling//
                if (RopeAboveBool != null)
                {
                    if (RopeAboveBool.GetComponent <BurningScript>().IsBurning == false)
                    {
                        RopeAboveBool.GetComponent <BurningScript>().IsBurning = true;
                    }
                }
                if (RopeBelowBool != null)
                {
                    if (RopeBelowBool.GetComponent <BurningScript>().IsBurning == false)
                    {
                        RopeBelowBool.GetComponent <BurningScript>().IsBurning = true;
                    }
                }
                //Add any executable code here!//



                /////////////////////////////////
            }
            if (Counter == 300)
            {
                GetComponent <HingeJoint2D>().enabled   = false;
                GetComponent <SpriteRenderer>().enabled = false;
                GetComponent <BoxCollider2D>().enabled  = false;

                Destroy(burningObject);

                ObjectThatShouldFall objectThatShouldFallScript = transform.root.GetChild(0).GetComponent <ObjectThatShouldFall>();
                objectThatShouldFallScript.ObjectIsFalling();
            }
        }
    }