Example #1
0
    // Update is called once per frame
    void Update()
    {
        PickUpDipositeBlock pickUpBlock         = GetComponentInParent <PickUpDipositeBlock>();
        DipositeBlock       dipositeBlock       = GetComponentInParent <DipositeBlock>();
        PickUpDipositeBlock pickUpDipositeBlock = GetComponentInParent <PickUpDipositeBlock>();


        if (pickUpBlock)
        {
            pickableObject = pickUpBlock.ownPickableObject;
        }
        else if (dipositeBlock)
        {
            pickableObject = dipositeBlock.ownPickableObject;
        }
        else if (pickUpDipositeBlock)
        {
            pickableObject = pickUpDipositeBlock.ownPickableObject;
        }

        if (!(wasShake) && pickableObject != null)
        {
            modelTransformBefore = modelToShake.transform.position;
            StartCoroutine(_modelShake(0.1f));
            wasShake = true;
            pickableObject.transform.position = new Vector3(transform.position.x, pickableObject.transform.position.y, transform.position.z);
        }
        if (pickableObject == null)
        {
            wasShake = false;
        }
    }
Example #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!playerIndexSet || !prevState.IsConnected)
        {
            for (int i = 0; i < 4; ++i)
            {
                PlayerIndex  testPlayerIndex = (PlayerIndex)i;
                GamePadState testState       = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected && i == controller.playerIndex)
                {
                    playerIndex    = testPlayerIndex;
                    playerIndexSet = true;
                }
            }
        }

        prevState = state;
        state     = GamePad.GetState(playerIndex);

        if (state.ThumbSticks.Left.X != 0 || state.ThumbSticks.Left.Y != 0)
        {
            /*
             * float angle = 0;
             * if (controller.Left)
             *  angle = 270;
             * else if (controller.Right)
             *  angle = 90;
             * else if (controller.Up)
             *  angle = 0;
             * else
             *  angle = 180;*/


            horizontalAxis = state.ThumbSticks.Left.X;
            verticalAxis   = state.ThumbSticks.Left.Y;
            var tmp = new Vector3(state.ThumbSticks.Left.X, 0, state.ThumbSticks.Left.Y);
            if (Mathf.Abs(horizontalAxis) > Mathf.Abs(verticalAxis))
            {
                verticalAxis = 0;
            }
            else
            {
                horizontalAxis = 0;
            }

            forward.transform.eulerAngles = new Vector3(0, Mathf.Atan2(horizontalAxis, verticalAxis) * Mathf.Rad2Deg, 0);

            if (forward.eulerAngles.y == 270)
            {
                if (!PickableObject)
                {
                    spriteRenderer.sprite = m_sprites[1];
                }
                else
                {
                    spriteRenderer.sprite = m_sprites[2];
                }
                spriteRenderer.flipX = true;
            }
            else
            {
                spriteRenderer.flipX = false;
                if (forward.eulerAngles.y == 90)
                {
                    if (!PickableObject)
                    {
                        spriteRenderer.sprite = m_sprites[1];
                    }
                    else
                    {
                        spriteRenderer.sprite = m_sprites[2];
                    }
                }
                if (forward.eulerAngles.y == 180)
                {
                    if (!PickableObject)
                    {
                        spriteRenderer.sprite = m_sprites[3];
                    }
                    else
                    {
                        spriteRenderer.sprite = m_sprites[0];
                    }
                }
                if (forward.eulerAngles.y == 0)
                {
                    if (!PickableObject)
                    {
                        spriteRenderer.sprite = m_sprites[5];
                    }
                    else
                    {
                        spriteRenderer.sprite = m_sprites[4];
                    }
                }
            }

            //transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, Mathf.Atan2(controller.HorizontalAxis, controller.VerticalAxis) * Mathf.Rad2Deg, 0), settings.Smoothness);
            myRigidbody.velocity = forward.forward * settings.Speed;

//            FMODUnity.RuntimeManager.PlayOneShot(footStepEvent, transform.position);
        }
        else
        {
            myRigidbody.velocity = Vector3.zero;
        }

        ComputeRaycast();

        bool pickUp = prevState.Buttons.X == ButtonState.Released && state.Buttons.X == ButtonState.Pressed;

        if (blockToToInteract && pickUp)
        {
            blockToToInteract.OnInteract(this);

            PickUpBlock         pickUpBlock         = blockToToInteract.GetComponent <PickUpBlock>();
            DipositeBlock       dipositeBlock       = blockToToInteract.GetComponent <DipositeBlock>();
            PickUpDipositeBlock pickUpDipositeBlock = blockToToInteract.GetComponent <PickUpDipositeBlock>();

            if (pickUpBlock)
            {
                if (!PickableObject)
                {
                    PickableObject pickableObject = pickUpBlock.PickUp();
                    if (pickableObject)
                    {
                        PickableObject = pickableObject;
                    }
                }
            }

            if (dipositeBlock)
            {
                if (PickableObject)
                {
                    if (dipositeBlock.Diposide(PickableObject))
                    {
                        PickableObject = null;
                    }
                }
            }

            if (pickUpDipositeBlock)
            {
                bool canPickUp = false;
                if (PickableObject)
                {
                    canPickUp = pickUpDipositeBlock.Diposide(PickableObject);
                    if (canPickUp)
                    {
                        PickableObject = null;
                    }
                    //PickableObject.transform.SetParent(null);
                }

                if (!canPickUp && !PickableObject)
                {
                    PickableObject pickableObject = pickUpDipositeBlock.PickUp();

                    if (pickableObject)
                    {
                        PickableObject = pickableObject;
                        return;
                    }
                }
            }
        }
    }