// Update is called once per frame
    void Update()
    {
        coinText.GetComponent <Text>().text = "" + currentCoin.ToString() + "/5";

        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }



        IEnumerator Reset(float Count)
        {
            yield return(new WaitForSeconds(Count));

            yield return(null);
        }

        if (health <= 0)
        {
            //PlaySound(dieSound);
            Invoke("Restart", 3.0f);
        }

        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            SceneManager.LoadScene("RubyFinal2");
        }

        if ((Input.GetKeyDown(KeyCode.C) && currentAmmo > 0))
        {
            Launch();
            currentAmmo -= 1;
        }
        ammoText.GetComponent <Text>().text = currentAmmo.ToString();

/////
        if ((Input.GetKeyDown(KeyCode.D) && currentRedAmmo > 0))
        {
            Launch2();
            currentRedAmmo -= 1;
        }
        ammoRedText.GetComponent <Text>().text = currentRedAmmo.ToString();
        //////

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
        //
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC2"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
//


        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    Debug.Log(RobotsFixed.instance.robotsFixed);
                    if ((RobotsFixed.instance.robotsFixed == 6 && currentCoin == 5))
                    {
                        character.DisplayDialog2();
                        StartCoroutine(WaitForSec());
                    }
                    IEnumerator WaitForSec()
                    {
                        yield return(new WaitForSeconds(4));

                        SceneManager.LoadScene("RubyFinal2");
                    }
                }
            }
        }


        //
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC2"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    Debug.Log(RobotsFixed.instance.robotsFixed);
                    if ((RobotsFixed.instance.robotsFixed == 6 && currentCoin >= 5))
                    {
                        character.DisplayDialog2();

                        audioSource.Play();
                        speed = 0;
                    }
                }
            }
        }
        //


        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("Cube"));
            if (hit.collider != null)
            {
                ResourceCube rc = hit.collider.GetComponent <ResourceCube>();
                if (rc != null)
                {
                    PlaySound(findSound);
                    rc.BlownUp();
                }
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (currentHealth == 0)
        {
            if (Input.GetKey(KeyCode.R) & level == 1)
            {
                SceneManager.LoadScene("Stage1");
            }

            if (Input.GetKey(KeyCode.R) & level == 2)
            {
                SceneManager.LoadScene("Stage2");
            }
        }

        Scoretext();
        Cointext();

        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            if (cogs > 0)
            {
                Launch();
                cogs          = cogs - 1;
                cogstext.text = "cogs:" + cogs.ToString();
            }
        }

        if (score == 4 & level == 1)
        {
            conditionaltext.text = "Talk to Jambi to visit stage 2";

            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                if (Input.GetKeyDown(KeyCode.X))
                {
                    SceneManager.LoadScene("Stage2");
                    level++;
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));

            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();

                if (character != null)
                {
                    if (score < 4 | coins < 4)
                    {
                        PlaySound(npcinteraction);
                        character.DisplayDialog();
                    }

                    else if (score == 4 & level == 1)
                    {
                        character.DisplayDialog3();
                    }

                    else if (coins == 4 & level == 2)
                    {
                        character.DisplayDialog2();
                        conditionaltext.text = "You Win! Game Created by Matthew Falconett. Press R to restart";
                        musicsource.clip     = victorymusic;
                        musicsource.Play();
                        speed = 0;
                        coins = 5;
                        level = 3;
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.R) && level == 3)  //Restart for winning
        {
            SceneManager.LoadScene("Stage2");
            level = 2;
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null & coins == 4)
            {
                SceneManager.LoadScene("Stage2");
            }
        }


        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }


        if (powerup)
        {
            poweruptimer += Time.deltaTime;

            if (poweruptimer >= 2)
            {
                speed        = 3;
                poweruptimer = 0;
                powerup      = false;
            }
        }
    }