Esempio n. 1
0
    public override void OnDestroy()
    {
        RaycastHit hitInfo;

        if (Physics.Raycast(barrel.transform.position, barrel.transform.forward, out hitInfo, Mathf.Infinity))
        {
            if (hitInfo.collider != null)
            {
                //we hit a collider
                GameCube cube = hitInfo.collider.GetComponent <GameCube> ();

                if (cube != null)
                {
                    cube.OnPointedAway();
                }
            }
        }
        base.OnDestroy();
    }
Esempio n. 2
0
    protected override void HandAttachedUpdate(Hand hand)
    {
        base.HandAttachedUpdate(hand);

        HandControls hc = ControlsManager.Instance.GetControlsFromHand(hand);

        //Update other components when held
        foreach (IHeldUpdateable hu in heldUpdateables)
        {
            hu.HeldUpdate();
        }

        //Raycasting comes last as returning form the function is an option

        RaycastHit hitInfo;

        if (Physics.Raycast(barrel.transform.position, barrel.transform.forward, out hitInfo, Mathf.Infinity))
        {
            if (hitInfo.collider != null)
            {
                //we hit a collider
                GameCube cube = hitInfo.collider.GetComponent <GameCube> ();

                if (cube != null)
                {
                    //When we look at a different cube or the cube we look at changes
                    if (updateUI == true || lastPointedAt != cube || lastPointedAtOccupying != cube.Occupying)
                    {
                        brProgressBar.ActOnCubeTimer = 0f;

                        if (lastPointedAt != null)
                        {
                            lastPointedAt.OnPointedAway();
                        }

                        if (currentID >= 0)
                        {
                            canUpdate = cube.OnPointedAt(buildables [currentID].GetComponent <IPlaceable> (), this);
                        }
                        else
                        {
                            canUpdate = cube.OnPointedAt(null, this);
                        }
                        updateUI = false;
                    }

                    //Called every frame that we point to the cube
                    lastPointedAt          = cube;
                    lastPointedAtOccupying = cube.Occupying;

                    if (hc.TriggerPulled.Any && built == false)
                    {
                        if (brProgressBar.ActOnCubeTimer <= 0)
                        {
                            aSource.clip = buildChargeClip;
                        }

                        if (aSource.isPlaying == false)
                        {
                            aSource.time = Mathf.Min(aSource.clip.length, brProgressBar.ActOnCubeTimer);
                            aSource.Play();
                        }

                        brProgressBar.ActOnCubeTimer += Time.deltaTime;


                        if (brProgressBar.ActOnCubeTimer >= brProgressBar.holdToActTime)
                        {
                            ActOnCube(cube);
                            brProgressBar.ActOnCubeTimer = 0f;
                            built    = true;
                            updateUI = true;
                        }
                    }
                    else
                    {
                        brProgressBar.ActOnCubeTimer = Mathf.Max(0f, brProgressBar.ActOnCubeTimer - (Time.deltaTime * 2f));
                        aSource.Stop();
                    }

                    if (hc.TriggerPulled.Up)
                    {
                        built = false;
                    }

                    return;
                }
            }
        }

        //missed cube tihs frame, but last frame was hitting a box
        if (lastPointedAt != null)
        {
            lastPointedAt.OnPointedAway();

            lastPointedAt = null;

            brProgressBar.ActOnCubeTimer = 0f;
        }
    }