Beispiel #1
0
    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            if (Input.GetKeyDown(keyToUse) && allowChangeScene)
            {
                HudText.EraseText();

                this.transform.localScale = inventoryScale;

                this.GetComponent <Collider>().isTrigger = false;
                BoxCollider col = this.GetComponent <Collider>() as BoxCollider;
                col.size   = inventoryColliderSize;
                col.center = inventoryColliderPosition;


                this.transform.parent = inventory.gameObject.transform;
                DontDestroyOnLoad(this.gameObject);

                if (!isSolid)
                {
                    inventory.AddReagentLiquid(reagent);
                    reagent.inInventory = true;
                }
                else
                {
                    inventory.AddReagentSolid(reagentSolid);
                }
            }
        }
    }
Beispiel #2
0
 //! The collider other has stopped touching the trigger.
 void OnTriggerExit(Collider other)
 {
     if (other.tag == "Player" && allowGetData)
     {
         HudText.EraseText();
     }
 }
Beispiel #3
0
    // Update is called once per frame
    //! Processing precision errors.
    void Update()
    {
        if (allowShowFloat)
        {
            if (Time.time - timeToUpdateValueAcc > timeToUpdateValue)
            {
                string errorStringForm = "0";
                if (errorPrecision > 0)
                {
                    errorStringForm = "0.";
                    for (int i = 0; i < errorPrecision; i++)
                    {
                        errorStringForm += "0";
                    }
                }
                textResult.text      = applyErrorInFloat(resultFloat).ToString(errorStringForm);
                timeToUpdateValueAcc = Time.time;
            }
        }

        if (allowShowTexture)
        {
            if (rendererResult != null)
            {
                rendererResult.material.mainTexture = resultTexture;
            }
            allowShowTexture = false;
        }

        if (Time.time - timeToShowPrintTextAcc > timeToShowPrintText)
        {
            timeToShowPrintTextAcc = Mathf.Infinity;
            HudText.EraseText();
        }
    }
 //! Collider other has stopped touching the trigger.
 void OnTriggerExit(Collider other)
 {
     if (other.tag == "Player")
     {
         allowChangeScene = false;
         HudText.EraseText();
     }
 }
    //! Set positons (player) and rotation (camera).
    /*! Is sent to the trigger and the collider that touches the trigger.*/
    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            if (Input.GetKeyDown(keyToUse))
            {
                HudText.EraseText();

                PlayerPrefs.SetFloat("PlayerPosX", other.transform.position.x);
                PlayerPrefs.SetFloat("PlayerPosy", other.transform.position.y);
                PlayerPrefs.SetFloat("PlayerPosZ", other.transform.position.z);
                PlayerPrefs.SetFloat("RotationCameraX", Camera.main.transform.localEulerAngles.x);
                PlayerPrefs.SetFloat("RotationCameraY", Camera.main.transform.localEulerAngles.y);
                PlayerPrefs.SetFloat("RotationCameraZ", Camera.main.transform.localEulerAngles.z);
                PlayerPrefs.Save();
                Application.LoadLevel(sceneToGo);

                InventoryController inventory = FindObjectOfType(typeof(InventoryController)) as InventoryController;
            }
        }
    }
Beispiel #6
0
    //! Is called almost all the frames for every collider other that is touching the trigger.
    /*! This message is sent to the trigger and the collider that touches the the trigger. */
    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player" && allowGetData)
        {
            if (Input.GetKeyDown(keyToUse))
            {
                HudText.EraseText();
                allowGetData = false;

                //! Add the chart in inventory
                foreach (Texture2D item in pressSheets)
                {
                    Chart graph = Instantiate(chartPrefab) as Chart;
                    graph.transform.parent = inventory.transform;
                    graph.SetChart(item);
                    graph.gameObject.layer = 10;
                    inventory.AddChart(graph);
                }

                pressSheets.Clear();
            }
        }
    }
Beispiel #7
0
    void Update()
    {
        if (inInteraction)
        {
            motor.movement.velocity = Vector3.zero;
            transform.position      = lastPosition;
            currentDelay           += Time.deltaTime;
            if (currentDelay > delayInteract)
            {
                currentDelay  = 0;
                inInteraction = false;
            }
            return;
        }

        // Get the input vector from kayboard or analog stick
        Vector3 directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        if (directionVector != Vector3.zero)
        {
            // Get the length of the directon vector and then normalize it
            // Dividing by the length is cheaper than normalizing when we already have the length anyway
            float directionLength = directionVector.magnitude;
            directionVector = directionVector / directionLength;

            // Make sure the length is no bigger than 1
            directionLength = Mathf.Min(1.0f, directionLength);

            // Make the input vector more sensitive towards the extremes and less sensitive in the middle
            // This makes it easier to control slow speeds when using analog sticks
            directionLength = directionLength * directionLength;

            // Multiply the normalized direction vector by the modified length
            directionVector = directionVector * directionLength;
        }

        // Apply the direction to the CharacterMotor
        if (!keysLocked)
        {
            motor.inputMoveDirection = transform.rotation * directionVector;
            //motor.inputJump = Input.GetButton ("Jump");
        }

        // Implements Raycast to get which object is being Hit and how to interact with it.
        Ray        cameraRay = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, Mathf.Infinity));
        RaycastHit hitInfo;


        if (Physics.Raycast(cameraRay, out hitInfo, Mathf.Infinity))
        {
            bool nameReset = false;
            if (hitInfo.collider.GetComponent <AccessEquipmentBehaviour> ())
            {
                if (hitInfo.collider.gameObject.Equals(lastHit.collider.gameObject))
                {
                    nameReset = true;
                    hitInfo.collider.GetComponent <AccessEquipmentBehaviour> ().SetTrigger(true);
                    HudText.SetText(hitInfo.collider.GetComponent <AccessEquipmentBehaviour> ().equipName);
                    if (hitInfo.distance > 3)
                    {
                        hitInfo.collider.GetComponent <AccessEquipmentBehaviour> ().setCanvasAlpha(1f);
                    }
                    else
                    {
                        hitInfo.collider.GetComponent <AccessEquipmentBehaviour> ().setCanvasAlpha(0.5f * hitInfo.distance - 0.5f);
                    }
                }
                else
                if (lastHit.collider.GetComponent <AccessEquipmentBehaviour> () != null)
                {
                    lastHit.collider.GetComponent <AccessEquipmentBehaviour> ().SetTrigger(false);
                }
            }
            else if (lastHit.collider.GetComponent <AccessEquipmentBehaviour> () != null)
            {
                lastHit.collider.GetComponent <AccessEquipmentBehaviour> ().SetTrigger(false);
            }
            if (hitInfo.collider.GetComponent <InteractObjectBase> () && hitInfo.distance <= distanceToInteract)
            {
                if (Input.GetKeyDown(KeyCode.E))
                {
                    hitInfo.collider.GetComponent <InteractObjectBase> ().Interact();
                    if (!hitInfo.collider.GetComponent <AccessEquipmentBehaviour> ())
                    {
                        gameObject.GetComponent <PlayerAnimation> ().PlayInteractAnimation();
                    }
                    inInteraction = true;
                    lastPosition  = transform.position;
                }
                HudText.SetText(interactText);
            }
            else
            {
                if (!nameReset)
                {
                    HudText.EraseText();
                }
            }
            //show information about the object

            lastHit = hitInfo;
        }


        //State Machine for the different uses of input
        //HUD components:

        /*if (Input.GetKeyDown (KeyCode.Escape)) {
         *      hudController.menu.Pause ();
         * }
         * if(Input.GetKeyDown(hudController.journalKey)&&!hudController.lockKey){
         *      hudController.CallTabletTrigger();
         * }
         * if ((Input.GetKeyDown (hudController.inventoryKey))&&!hudController.lockKey) {
         *      hudController.CallInventoryTrigger();
         * }
         * if((Input.GetKeyDown(hudController.mapKey))&&!hudController.lockKey){
         *      hudController.CallMapTrigger();
         * }
         *
         * //End of states
         * if (gameController.GetCurrentState () == gameController.gameStates [0]) {
         *
         * }*/
    }