Пример #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        GetSideHit.HitDirection hitSide = GetSideHit.HitDirection2Test(col);
        Debug.Log(hitSide);


        if (hitSide == GetSideHit.HitDirection.Left || hitSide == GetSideHit.HitDirection.Right)
        {
            if (movingLeft)
            {
                movingLeft = false;
            }
            else
            {
                movingLeft = true;
            }
        }
        else if (powerUpType == PowerUpType.Starman && hitSide == GetSideHit.HitDirection.Bottom)
        {
            thisRigidBody.velocity = new Vector2(0, 6f);
        }
    }
    //=======================================================================================================================
    //=======================================================================================================================

    // Start is called before the first frame update
    void Start()
    {
        movementScript = GetComponent <Movement>();
        getSideHit     = GetComponent <GetSideHit>();
    }
Пример #3
0
    void Collided(Collision2D col)
    {
        Debug.Log("YEAH");
        try {
            if (col.collider.transform.childCount != 0)
            {
                if (col.collider.transform.GetChild(0).name == "ColForOtherObjects")
                {
                    if (col.collider.transform.GetChild(0).GetComponent <Shells>() != null)
                    {
                        Debug.Log("Yo");
                        //We hit another shell, likely.
                        if (status != Status.Idle)
                        {
                            shellAudio.clip = shellSmack;
                            shellAudio.Play();
                            if (col.collider.transform.GetChild(0).GetComponent <Shells>().status == Status.Idle)
                            {
                                col.gameObject.SendMessage("Death");
                                Destroy(col.transform.GetChild(0).gameObject);
                            }
                            else
                            {
                                col.gameObject.SendMessage("Death");
                                Destroy(col.transform.GetChild(0).gameObject);
                                gameObject.transform.parent.SendMessage("Death");
                                Destroy(gameObject);
                            }
                        }
                        else
                        {
                            if (col.transform.GetChild(0).GetComponent <Shells>().status != Status.Idle && status == Status.Idle)
                            {
                                Debug.Log("Shell broken.");

                                transform.parent.SendMessage("Death");
                                if (grabbed)
                                {
                                    GameObject.FindGameObjectWithTag("Player").SendMessage("ItemInHandDestroyed");
                                }
                                Destroy(gameObject);
                            }
                        }
                    }
                }
            }
            else
            {
                if (status != Status.Idle)
                {
                    //Likely a wall.
                    GetSideHit.HitDirection hitDir = GetSideHit.HitDirection2Test(col);
                    Debug.Log(hitDir);
                    if (hitDir == GetSideHit.HitDirection.Left || hitDir == GetSideHit.HitDirection.Right)
                    {
                        col.gameObject.SendMessage("Activated", this, SendMessageOptions.DontRequireReceiver);
                        if (hitDir == GetSideHit.HitDirection.Left)
                        {
                            movingLeft = false;
                        }
                        else
                        {
                            movingLeft = true;
                        }

                        shellAudio.clip = shellPivot;
                        shellAudio.Play();
                    }
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogWarning("Caught a Exception: " + e.Message);
            Debug.LogWarning(e.StackTrace);
        }
    }