Exemplo n.º 1
0
//	void Awake() {
//		DontDestroyOnLoad (transform.gameObject);
//	}

    void Update()
    {
        timesincelastattack += Time.deltaTime;
        //Debug.Log (myInfo.timeElapsed);
        isObserved = observedArray[0];
        for (int i = 1; i < observedArray.Length; i++)
        {
            isObserved = observedArray[i] && isObserved;
        }
        bool allDoors    = doorArray[0];
        bool allSwitches = switchArray[0];
        bool allScenes   = sceneArray[0];

        for (int i = 1; i < doorArray.Length; i++)
        {
            allDoors = doorArray[i] || allDoors;
        }
        for (int i = 1; i < switchArray.Length; i++)
        {
            allSwitches = switchArray[i] || allSwitches;
        }
        for (int i = 1; i < sceneArray.Length; i++)
        {
            allScenes = sceneArray[i] || allScenes;
        }
        if (!allDoors && !allSwitches && !moralChoice)
        {
            textbox2.GetComponent <Text>().text = "";
        }
        if (!allScenes)
        {
            textbox3.GetComponent <Text>().text = "";
        }
        if (!allDoors && !allSwitches && !moralChoice && !allScenes)
        {
            stupidBar.SetActive(false);
        }
        else
        {
            stupidBar.SetActive(true);
        }
        openDoor = false;
        textbox.GetComponent <Text>().text        = "x " + keyCount;
        textboxhealth.GetComponent <Text> ().text = "x " + healthKits;
        health0.SetActive(false);
        health1.SetActive(false);
        health2.SetActive(false);
        health3.SetActive(false);
        health4.SetActive(false);
        health5.SetActive(false);

        // Add !isObserved to make health bar only visible during combat

        if (myHealth <= 0)
        {
            health0.SetActive(true);
        }
        else if (myHealth == 1)
        {
            health1.SetActive(true);
        }
        else if (myHealth == 2)
        {
            health2.SetActive(true);
        }
        else if (myHealth == 3)
        {
            health3.SetActive(true);
        }
        else if (myHealth == 4)
        {
            health4.SetActive(true);
        }
        else if (myHealth == 5)
        {
            health5.SetActive(true);
        }
        if (!isDead)
        {
            Vector3 right = transform.position + Vector3.right * transform.lossyScale.x * 0.25f + Vector3.down * 0.15f;
            Vector3 left  = transform.position - Vector3.right * transform.lossyScale.x * 0.25f + Vector3.down * 0.15f;

            Debug.DrawLine(right, right + (Vector3.down * transform.lossyScale.y * 0.4f));
            Debug.DrawLine(left, left + (Vector3.down * transform.lossyScale.y * 0.3f));
            Debug.DrawLine(right, right + (Vector3.up * transform.lossyScale.y * 0.3f));
            Debug.DrawLine(left, left + (Vector3.up * 0.4f));

            onSomething = Physics.Linecast(right, right + (Vector3.down * transform.lossyScale.y * 0.3f), 1 << LayerMask.NameToLayer("Obstacle") | 1 << LayerMask.NameToLayer("Enemy")) ||
                          Physics.Linecast(left, left + (Vector3.down * transform.lossyScale.y * 0.3f), 1 << LayerMask.NameToLayer("Obstacle") | 1 << LayerMask.NameToLayer("Enemy"));

            underSomething = Physics.Linecast(right, right + (Vector3.up * transform.lossyScale.y * 0.3f), 1 << LayerMask.NameToLayer("Obstacle")) ||
                             Physics.Linecast(left, left + (Vector3.up * transform.lossyScale.y * 0.3f), 1 << LayerMask.NameToLayer("Obstacle"));



            //Debug.Log(beginCutScene);
            if (!beginCutScene)
            {
                if (Input.GetKey(KeyCode.LeftArrow) && (!isAttacking || isAttacking && movingLeft))
                {
                    movingLeft = true;
                    Vector3 s = transform.localScale;
                    s.x = -2;
                    transform.localScale = s;
                }
                else
                {
                    movingLeft = false;
                }
                if (Input.GetKey(KeyCode.RightArrow) && (!isAttacking || isAttacking && movingRight))
                {
                    movingRight = true;
                    Vector3 s = transform.localScale;
                    s.x = 2;
                    transform.localScale = s;
                }
                else
                {
                    movingRight = false;
                }

//				if (Input.GetKey (KeyCode.D) && Input.GetKey (KeyCode.A)) {
//					movingLeft = false;
//					movingRight = false;
//				}

                if (Input.GetKeyDown(KeyCode.UpArrow) && onSomething && !crouching)
                {
                    jump          = true;
                    timesincejump = 0f;
//					GetComponent<Renderer>().material.mainTexture = jumpSprite;
                }

                if (Input.GetKey(KeyCode.DownArrow))
                {
                    crouching = true;
//					GetComponent<Renderer>().material.mainTexture = crouchSprite;
                }
                if (!Input.GetKey(KeyCode.DownArrow) && !underSomething && onSomething)
                {
                    crouching = false;
//					GetComponent<Renderer>().material.mainTexture = walkSprite;
                }

                if (Input.GetKey(KeyCode.D))
                {
                    openDoor = true;
                }


                if (Input.GetKey(KeyCode.A) && !crouching && onSomething && timesincelastattack > 0.5f && !gettingHit)
                {
                    biteSound.Play();
                    if (nearEnemy)
                    {
                        if (nearestEnemy != null)
                        {
                            nearestEnemy.takeDamage(1);
                        }
                        else
                        {
                            nearestBoss.takeDamage(1);
                        }
                    }
                    isAttacking         = true;
                    timesincelastattack = 0f;
                }
                else
                {
                    if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
                    {
                        isAttacking = false;
                    }
                }


                if (Input.GetKey(KeyCode.E))
                {
                    if (healthKits > 0)
                    {
                        myHealth = Mathf.Min(myHealth + 2, 5);
                        healthKits--;
                    }
                }
            }
            else
            {
                movingLeft  = false;
                movingRight = false;
            }
        }
        else
        {
            transform.rotation = Quaternion.Euler(0f, 0f, 180f);
            myRb.velocity      = new Vector3(0f, myRb.velocity.y, 0f);
        }

        if (gettingHit)
        {
            velocity          = 0f;
            timesincelasthit += Time.deltaTime;
            if (timesincelasthit > 0.5f)
            {
                gettingHit = false;
            }
        }
        anim.SetBool("Ground", onSomething);
        anim.SetFloat("vSpeed", myRb.velocity.y);
        anim.SetFloat("Speed", Mathf.Abs(myRb.velocity.x));
        anim.SetBool("isCrawling", crouching);
        anim.SetBool("isJumping", jump);
        anim.SetBool("isAttacking", isAttacking);
        anim.SetBool("isHit", gettingHit);
//		anim.SetBool ("isHit", false);
    }