Example #1
0
    // Update is called once per frame
    void Update()
    {
        // -- INPUT --
        if (carriableInHands)
        {
            //Special case where we are near the spaceship and are carrying a spaceship part
            if (nearSpaceship)
            {
                if (Input.GetKeyDown(KeyCode.E))
                {
                    if (carriableInHands.spaceshipPart != SpaceshipPart.None)
                    {
                        switch (carriableInHands.spaceshipPart)
                        {
                        case SpaceshipPart.Booster:
                            spaceship.fixBooster();
                            break;

                        case SpaceshipPart.Cube:
                            spaceship.fixPowerCube();
                            break;

                        case SpaceshipPart.Fuel:
                            spaceship.fixFuel();
                            break;

                        case SpaceshipPart.Leg:
                            spaceship.fixLeg();
                            break;
                        }
                        Destroy(carriableInHands.gameObject);
                        carriableInHands = null;
                        Unequip();
                        return;
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                carriableInHands.ActivateEffect(this);
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                Unequip();
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                Collider[] hits = Physics.OverlapSphere(sphereCastOffset.position, 0.5f);
                Debug.Log(hits.Length);
                for (int i = 0; i < hits.Length; i++)
                {
                    CarriableObject carriableObject = hits[i].GetComponent <CarriableObject>();
                    if (carriableObject)
                    {
                        AudioSource.PlayClipAtPoint(audioClip, transform.position);
                        Equip(carriableObject);
                        break;
                    }
                }
            }
        }

        // -- OTHER --
        if (mustLerp)
        {
            // A bit expensive lerp
            carriableInHands.transform.localPosition = Vector3.Slerp(
                carriableInHands.transform.localPosition, Vector3.zero, Time.deltaTime * lerpSpeed);

            if (carriableInHands.transform.localPosition == Vector3.zero)
            {
                mustLerp = false;
            }
        }
    }