Esempio n. 1
0
    // Update is called once per frame
    private void Update()
    {
        // Set up horizontal and vertical movement with input commands.
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        // Stores directional inputs into a single vector
        Vector2 move = new Vector2(horizontal, vertical);

        // Check to see if move.x or move.y is 0
        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            // Set player sprite direction pointed towards move vector
            // Normalize to set the vector length to 1
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

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

        // Changes position based on physics and move vector
        Vector2 position = rigidbody2d.position;

        position += move * speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        // frames invincible in the case of taking damage, checked once per frame
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        // Press C to fire projectile
        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        // Press X to talk to NPC
        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();
                }
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        //gets the inputs from the player
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        //
        Vector2 move = new Vector2(horizontal, vertical);

        //if the player x || y does not equal 0, it means they are moving
        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            //set their directions
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }


        //plays the animations in which the direciton the palyer is moving in
        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        //if player is invincible
        if (isInvincible)
        {
            //remove time from invincibleTimer
            invincibleTimer -= Time.deltaTime;
            //if timer is less than 0
            if (invincibleTimer < 0)
            {
                //player is no longer invincible
                isInvincible = false;
            }
        }

        //key to fire projectiles
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            //function to fire projectiles
            Launch();
        }

        //key to talk to npcs
        if (Input.GetKeyDown(KeyCode.LeftAlt))
        {
            //creates a raycast with 4 parameters
            //starting point above the feet, the direction the player is looking in, how far to look, and the layer mask it should be interacting with
            RaycastHit2D hit = Physics2D.Raycast(rb2D.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            //if the hit collider hits something
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Esempio n. 3
0
    // Update is called once per frame
    private void Update()
    {
        Move();
        //countdown the time the player is invincible
        if (_isInvincible)
        {
            _invincibleTimer -= Time.deltaTime;
            if (_invincibleTimer < 0)
            {
                _isInvincible = false;
            }
        }

        //use input axes here
        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.C))
        {
            Launch();
        }
    }
    // Update is called once per frame
    void Update()
    {
        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();
        }

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


        // spilar hljod ef leikmadur er ad hlaupa
        if (move.magnitude >= 0.1 && !walkingAudioSource.isPlaying)
        {
            walkingAudioSource.Play();
        }
        else if (move.magnitude <= 0.1 && walkingAudioSource.isPlaying)
        {
            walkingAudioSource.Stop();
        }


        // leikmadur getur ekki tekið damage i akveðin tima
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
            PlaySound(throwingClip);
        }

        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();
                }
            }
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        if (Input.GetKey(KeyCode.R))

        {
            if (gameOver == true)

            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }

        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))
        {
            Launch();
        }

        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();
                }
            }
        }
    }
Esempio n. 6
0
    void Update()
    {
        // ================= HEALTH ====================
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        // ============== MOVEMENT ======================
        float horizontal = Input.GetAxis("Horizontal");
        float 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();
        }

        Vector2 position = rigidbody2d.position;

        position = position + move * speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);


        // ============== ANIMATION =======================

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

        // ============== PROJECTILE ======================

        if (Input.GetKeyDown(KeyCode.C))
        {
            LaunchProjectile();
        }

        // ======== DIALOGUE ==========
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, 1 << LayerMask.NameToLayer("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D       hit       = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
            if (hit.collider)
            {
                character.DisplayDialog();
            }
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }


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



        //Vector2 position = rigidbody2d.position;
        //position.x = position.x + speed * horizontal * Time.deltaTime;
        //position.y += speed * vertical * Time.deltaTime;

        //rigidbody2d.MovePosition(position);


        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);

        Vector2 position = rigidbody2d.position;

        position = position + move * speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);



        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
    }
Esempio n. 8
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        NonPlayerCharacter npc = gameObject.GetComponent <NonPlayerCharacter>();

        if (npc != null)
        {
            npc.DisplayDialog();
        }
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0f) || !Mathf.Approximately(move.y, 0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
            if (!audioSource.isPlaying)
            {
                audioSource.Play();
            }
        }
        else
        {
            if (audioSource.isPlaying)
            {
                audioSource.Stop();
            }
        }

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

        Vector2 position = rigidbody2d.position;

        position = position + move.normalized * speed * Time.deltaTime;
        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            PlaySound(cogClip);
            Launch();
        }
        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>();
                character.DisplayDialog();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        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 (ammo > 0)
            {
                Launch();
                ammo--;
                setAmmoText();
            }
        }

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

                CubeCollectible cube = hit.collider.GetComponent <CubeCollectible>();
                if (cube != null)
                {
                    cube.randomCollectible();
                }
            }
        }
    }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        Vector2 pos        = rigidbody2d.position;
        float   horizontal = Input.GetAxis("Horizontal");
        float   vertical   = Input.GetAxis("Vertical");
        //if (Input.GetKeyUp(KeyCode.Space)) {
        //    // animator.SetBool("Hit", true);
        //    //animator.SetTrigger("Launch");
        //    Launch();
        //}
        float fire = Input.GetAxis("Fire1");

        if (!Mathf.Approximately(fire, 0.0f))
        {
            Launch();
        }
        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)
            {
                //Debug.Log("Raycast has hit the object " + hit.collider.gameObject);
                NonPlayerCharacter npc = hit.collider.gameObject.GetComponent <NonPlayerCharacter>();
                if (npc != null)
                {
                    npc.DisplayDialog();
                }
            }
        }
        // Debug.Log(horizontal);
        pos.x += speed * horizontal * Time.deltaTime;
        pos.y += speed * vertical * Time.deltaTime;
        float moveSpeed = Mathf.Sqrt(horizontal * horizontal + vertical * vertical);

        //Debug.Log("move speed:" + moveSpeed + "," + horizontal + "," + vertical);
        if (!Mathf.Approximately(0.0f, horizontal) || !Mathf.Approximately(0.0f, vertical))
        {
            lookDirection.Set(horizontal, vertical);
            lookDirection.Normalize();
        }
        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", moveSpeed);
        // transform.position = pos;
        rigidbody2d.MovePosition(pos);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer <= 0)
            {
                isInvincible = false;
            }
        }
    }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float 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();
        }   //if

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

        Vector2 position = rb.position;

        position = position + characterSpeed * move * Time.deltaTime;

        rb.MovePosition(position);

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

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();

            PlaySound(collectedClip);
        }   //if

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rb.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
            }     //if
        }         //if
    }
Esempio n. 13
0
    // Update is called once per frame
    void Update()
    {
        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 (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 (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        //Debug.Log(horizontal);
        //Debug.Log(vertical);

        // Vector2 position = transform.position;
        // position.y = position.y + 3f * vertical * Time.deltaTime;
        // position.x = position.x + 3f * horizontal * Time.deltaTime;
        // transform.position = position;

        // If you want to make it work across devices, you can use Input.GetButtonDown with an axis name, like you did for movement, and define which button that axis corresponds to in the Input settings (Edit > Project Settings > Input). For an example, take a look at the Axes > Fire1.
        if (Input.GetKeyDown(KeyCode.C))
        //if (Input.GetButtonDown('Fire1'))
        {
            Launch();
        }
    }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        float   horizontal = Input.GetAxis("Horizontal");
        float   vertical   = Input.GetAxis("Vertical");
        Vector2 move       = new Vector2(horizontal, vertical);

#pragma warning disable CS0642 // Possible mistaken empty statement
        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            ;
        }
#pragma warning restore CS0642 // Possible mistaken empty statement
        {
            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);
        Vector2 position = rigidbody2d.position;
        position = position + move * speed * Time.deltaTime;
        rigidbody2d.MovePosition(position);
        if (isInvincible)
        {
            invincibleTimer = Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
            if (Input.GetKeyDown(KeyCode.C))
            {
                Launch();
            }
            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();
                    }
                }
            }
        }
        void Launch()
        {
            GameObject projectileObject = Instantiate(projectilePrefab, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
            Projectile projectile       = projectileObject.GetComponent <Projectile>();

            projectile.Launch(lookDirection, 300);
            animator.SetTrigger("Launch");
        }
    }
Esempio n. 15
0
    // Update is called once per frame
    void Update()
    {
        //moving character
        float vertical   = Input.GetAxis("Vertical");
        float horizontal = Input.GetAxis("Horizontal");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0f) || !Mathf.Approximately(move.y, 0f)) // check to see if move.x or move.y is NOT zero. Approximately helps with floats.
        {
            lookDirection.Set(move.x, move.y);                                    // if movement is detected, look direction is set per frame, then normalized (rounded)
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x); //sets floats in animator blend tree to determine what animation to play (left, right, up, down)
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        Vector2 position = rigidbody2d.position;             //gets current position from rigidbody

        position = position + move * speed * Time.deltaTime; // determining new player position

        rigidbody2d.MovePosition(position);                  // moves the player to position previously determined

        //invincibility timer when taking damage
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime; // counting down invincibility frames
            if (invincibleTimer < 0)
            {
                isInvincible = false; // disables invincibility if timer reaches zero
            }
        }

        if (Input.GetButtonDown("Fire1")) // checks per update to see if player pressed the attack button
        {
            Launch();
        }

        if (Input.GetButtonDown("Fire2")) // talk to NPCs
        {
            RaycastHit2D hit = Physics2D.Raycast(position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));

            if (hit.collider != null)
            {
                Debug.Log("Raycast has hit the object" + hit.collider.gameObject);
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Esempio n. 16
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal"); // Get set button from axes
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        // Check if moving
        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            // Set direction of character
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize(); // Normalize vector
        }

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

        Vector2 position = rigidbody2d.position;             // Create var and set to our pos

        position = position + move * speed * Time.deltaTime; // New pos

        rigidbody2d.MovePosition(position);                  // Set our pos to new pos

        if (isInvicible)
        {
            invicibleTimer -= Time.deltaTime;
            if (invicibleTimer < 0)
            {
                isInvicible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        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();
                }
            }
        }
    }
Esempio n. 17
0
    private void LaunchRaycast()
    {
        RaycastHit2D hit = Physics2D.Raycast(myRigidbody2D.position + Vector2.up * raycastPadding, lookDirection, raycastDistance, LayerMask.GetMask("NPC"));

        if (hit.collider)
        {
            NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
            if (character)
            {
                character.DisplayDialog();
            }
        }
    }
    // Update is called once per frame
    private void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float 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);

        Vector2 position = _rigidbody2D.position;

        position += move * (Speed * Time.deltaTime);

        _rigidbody2D.MovePosition(position);

        if (_isInvincible)
        {
            _invincibleTimer -= Time.deltaTime;
            if (_invincibleTimer < 0)
            {
                _isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        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();
                }
            }
        }
    }
Esempio n. 19
0
    // Update is called once per frame
    void Update()
    {
        // Get Input
        gHorizontal = Input.GetAxis("Horizontal");
        gVertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(gHorizontal, gVertical);

        // Talk action
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D tHit = Physics2D.Raycast(gRigidbody2d.position + Vector2.up * 0.2f, gLookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (tHit.collider != null)
            {
                Debug.Log("Raycast has hit the object " + tHit.collider.gameObject);
                if (tHit.collider != null)
                {
                    NonPlayerCharacter tCharacter = tHit.collider.GetComponent <NonPlayerCharacter>();
                    if (tCharacter != null)
                    {
                        tCharacter.DisplayDialog();
                    }
                }
            }
        }

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

        gAnimator.SetFloat("Look X", gLookDirection.x);
        gAnimator.SetFloat("Look Y", gLookDirection.y);
        gAnimator.SetFloat("Speed", move.magnitude);

        if (gIsInvincible)
        {
            gInvincibleTimer -= Time.deltaTime;
            if (gInvincibleTimer < 0)
            {
                gIsInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
            PlaySound(pCogThrowClip);
        }
    }
Esempio n. 20
0
    // Update is called once per frame
    void Update()
    {
        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))
        {
            Launch();
            PlaySound(TrowClip);
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            SceneManager.LoadScene("Menu");
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter jambi = hit.collider.GetComponent <NonPlayerCharacter>();
                if (jambi != null)
                {
                    jambi.DisplayDialog();
                }
            }
        }
    }
Esempio n. 21
0
 private void CheckKeyDownForCharacterInteraction()
 {
     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();
             }
         }
     }
 }
Esempio n. 22
0
    // Update is called once per frame
    void Update()
    {
        float   horizontal = Input.GetAxis("Horizontal");
        float   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);
        //Debug.Log(horizontal);
        Vector2 vector = rdbody2D.position;

        //vector.x += speed * horizontal*Time.deltaTime;
        //vector.y += speed * vertical*Time.deltaTime;
        vector += move * speed * Time.deltaTime;
        //transform.position = vector;
        rdbody2D.MovePosition(vector);
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rdbody2D.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter npc = hit.collider.GetComponent <NonPlayerCharacter>();
                if (npc != null)
                {
                    npc.DisplayDialog();
                    audioSource.PlayOneShot(talkClip);
                }
            }
        }
    }
Esempio n. 23
0
    // Update is called once per frame
    void Update()
    {
        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.GetButton("Jump") || Input.GetMouseButtonDown(0))
        {
            Debug.Log("fire");
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X) || Input.GetMouseButton(1))
        {
            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();
                }
            }
        }
    }
Esempio n. 24
0
    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);


        if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
        {
            IsJumping       = true;
            jumpTimeCounter = jumpTime;
            rb.velocity     = Vector2.up * jumpForce;
        }

        if (Input.GetKey(KeyCode.Space) && IsJumping == true)
        {
            SfxManager.sfxInstance.Audio.PlayOneShot(SfxManager.sfxInstance.Ejimas1);
            if (jumpTimeCounter > 0)
            {
                rb.velocity      = Vector2.up * jumpForce;
                jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                IsJumping = false;
            }
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
            IsJumping = false;
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
        {
            anim.SetBool("isRunning", true);
        }
        else
        {
            anim.SetBool("isRunning", false);
        }

        if (Input.GetKey(KeyCode.Space))
        {
            anim.SetTrigger("jumping");
        }

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


        if (maxHealth <= 0)
        {
            //Destroy(gameObject);
            SceneManager.LoadScene(sceneName: "Lose");
        }
    }
    private void Update()
    {
        mouseDir = (mousePos - rigidbody2d.position).normalized;

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

        moveDir = new Vector2(horizontal, vertical).normalized;

        if (Input.GetKeyDown(KeyCode.Space) && !isDashing && moveDir != Vector2.zero && dashCdTimer <= 0)
        {
            dashCdTimer        = cooldownDash;
            isDashing          = true;
            lastAfterImageTime = 0;
        }


        if (attackTime > 0)
        {
            attackTime -= Time.deltaTime;
        }

        if (launchCdTimer > 0)
        {
            launchCdTimer -= Time.deltaTime;
        }

        if (dashCdTimer > 0)
        {
            dashCdTimer -= Time.deltaTime;
        }

        Stab();

        if (Input.GetButtonDown("Fire1") && launchCdTimer <= 0)
        {
            launchCdTimer = cooldownLaunch;
            Launch();
        }
        else if (Input.GetButton("Fire2") && attackTime <= 0)
        {
            if (!Mathf.Approximately(mouseDir.x, 0.0f) || !Mathf.Approximately(mouseDir.y, 0.0f))
            {
                lookDirection.Set(mouseDir.x, mouseDir.y);
                lookDirection.Normalize();
            }

            attackTime = startTimeAttack;
            animator.SetTrigger("Launch");

            stabPos = mousePos;
            stabDir = mouseDir;
        }


        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();
                }

                Hostage hostage = hit.collider.GetComponent <Hostage>();
                if (hostage != null)
                {
                    if (hostage.target == null)
                    {
                        hostage.SetDestination(transform);
                    }
                    else
                    {
                        hostage.Heal(this);
                    }
                }
            }
        }

        if (isDashing && Time.time > lastAfterImageTime + dashAfterImageTimeInterval)
        {
            lastAfterImageTime = Time.time;
            GameObject afterImage = AfterImagePool.Instance.GetFromPool();
            afterImage.GetComponent <PlayerDashAfterImage>().Player = gameObject;
        }
    }
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        //vertical = Input.GetAxisRaw("Vertical");
        //Debug.Log(vertical);
        Vector2 move = new Vector2(horizontal * speed, rigidbody2d.velocity.y);

        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.GetButtonDown("Jump"))
        {
            if (isGrounded)
            {
                Jump();
                doubleJump = true;
            }
            else if (doubleJump)
            {
                Jump();
                doubleJump = false;
            }
        }

        //         if (Input.GetKeyDown(KeyCode.C))
        //         {
        //             Launch();
        //             PlaySound(throwingClip);
        //         }

        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();
                }
            }
        }
    }
Esempio n. 27
0
    // Update is called once per frame
    void Update()
    {
        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))
        {
            Launch();
        }
        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 (scoreValue >= 4)
                {
                    SceneManager.LoadScene("Challenge3");
                    level++;
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
        if (scoreValue >= 4)
        {
            winloseText.text = "Talk to Jambi to visit stage two!";


            if (Input.GetKey(KeyCode.R))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }
        if (currentHealth <= 0)
        {
            winloseText.text = "Game Over! Press R to Restart";
            if (Input.GetKey(KeyCode.R))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                audioSource.clip = backgroundmusic;
                audioSource.Play();
                audioSource.loop = true;
            }
            speed = 0.0f;
        }

        if (level == 2)
        {
            if (scoreValue >= 4)
            {
                winloseText.text = "You win! Game by: Alan Zeng";
                speed            = 0.0f;
            }
        }
    }
Esempio n. 28
0
    /// <summary>
    /// Handle movement,IFrames, user input
    /// </summary>
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float 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();
            GetComponent <AudioSource>().UnPause();
        }
        else
        {
            GetComponent <AudioSource>().Pause();
        }

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

        Vector2 position = rigidbody2d.position;

        moveSpeed = (Input.GetKey(KeyCode.LeftShift)) ? (speed * sprintSpeedMultiplier) : speed;

        position = position + move * moveSpeed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

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

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
            PlaySound(thrownClip);
        }

        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 (oppController.opponentsLeft != 0)
                    {
                        //begin text
                        character.DisplayDialog(false);
                    }
                    else
                    {
                        //complete text
                        character.DisplayDialog(true);
                        PlaySound(questComplete);
                    }
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            Debug.Log(oppController.opponentsLeft);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!gameOverState)
        {
            horizontal = Input.GetAxis("Horizontal");
            vertical   = Input.GetAxis("Vertical");


            Vector2 position = rigidbody2d.position;
            position.x = position.x + speed * horizontal * Time.deltaTime;
            position.y = position.y + speed * vertical * Time.deltaTime;

            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();
                startedRunning = true;
            }
            else if (Mathf.Approximately(move.x, 0.0f) || Mathf.Approximately(move.y, 0.0f))
            {
                isRunning      = false;
                startedRunning = false;
                runningAudio.Stop();
            }

            if (startedRunning && !isRunning)
            {
                isRunning = true;
                runningAudio.Play();
            }


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

            position = position + move * speed * Time.deltaTime;

            rigidbody2d.MovePosition(position);

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

            if (Input.GetKeyDown(KeyCode.C))
            {
                Launch();
                characterOneShot(cogThrowClip);
            }

            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();
                    }
                }
            }

            DamagaeFlash(false);
            HealFlash(false);
        }
    }
Esempio n. 30
0
    // Update is called once per frame, i.e. every time the game computes a new image (an uncertain rate)
    // It could be 20 images per second on a slow computer, or 3000 on a very fast one
    // To give the impression of movement, a game (just like a movie) is still images that are shown at high speed. Typically in games, 30 or 60 images show in one second. Each of those images is called a frame.
    // In this Update function, you will write anything you want to happen continuously in the game (for example, reading input from the player, moving GameObjects, or counting time passing).
    void Update()
    {
        // make the Ruby GameObject move
        horizontal = Input.GetAxis("Horizontal");                                     // be ready to tie the character's movement to keyboard input
                                                                                      // keyboard input through axes
                                                                                      // It stores the result that Input.GetAxis ("Horizontal") provides
                                                                                      // using the Unity Input System, which is composed of Input Settings and input code
                                                                                      // which Unity gives you to query the value of an axis for that frame
        vertical = Input.GetAxis("Vertical");                                         // The default axis corresponding to the key up and down is called Vertical

        /*Debug.Log(horizontal);*/                                                    // Debug contains all functions that help debug your game

        Vector2 move = new Vector2(horizontal, vertical);                             // Instead of doing x and y independently for the movement, you store the input amount in a Vector2 called move

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) // Check to see whether move.x or move.y isn’t equal to 0
        // Use Mathf.Approximately instead of == because the way computers store float numbers means there is a tiny loss in precision
        // you should never test for perfect equality
        // because an operation that should end up giving 0.0f could instead give something like 0.0000000001f instead
        {
            lookDirection.Set(move.x, move.y); // If either x or y isn’t equal to 0, then Ruby is moving, set your look direction to your Move Vector and Ruby should look in the direction that she is moving.
                                               // If she stops moving (Move x and y are 0) then that won’t happen and look will remain as the value it was just before she stopped moving.
                                               // equal to lookDirection = move
            lookDirection.Normalize();         // In general, you will normalize vectors that store direction because length is not important, only the direction is
        }

        animator.SetFloat("Look X", lookDirection.x); // send the direction you look in and the speed (the length of the move vector) to the Animator
        // If Ruby doesn’t move, it will be 0, but if she does then it will be a positive number.
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime; // if Ruby is invincible, you remove deltaTime from your timer
            if (invincibleTimer < 0)           // When that time is less than or equal to zero, the timer reaches its end and Ruby’s invincibility is finished,
            {
                isInvincible = false;          // so you remove her invincibility by resetting the bool to false
            }
        }

        if (Input.GetKeyDown(KeyCode.C)) // when the player presses a key, and call Launch when they do
        {
            Launch();                    // launch a Cog
        }

        if (Input.GetKeyDown(KeyCode.X)) // if the “talk” button is pressed, enter the if block and start your Raycast
        {
            // RaycastHit2D is a variable stores the result of a Raycast, which is given to us by Physics2D.Raycast
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2D.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            // The starting point is an upward offset from Ruby’s position because you want to test from the centre of Ruby’s Sprite, not from her feet.
            // The direction, which is the direction that Ruby is looking
            // A layer mask which allows us to test only certain layers. Any layers that are not part of the mask will be ignored during the intersection test.
            if (hit.collider != null)                                                            // If the Raycast didn’t intersect anything, this will be null so do nothing
                                                                                                 // Otherwise, RaycastHit2D will contain the Collider the Raycast intersected
            {
                /*Debug.Log("Raycast has hit the object " + hit.collider.gameObject);*/          // log the object you have just found with the Raycast
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>(); // trying to find a NonPlayerCharacter script on the object the Raycast hit
                if (character != null)                                                           // if that script exists on that object, you will display the dialog
                {
                    character.DisplayDialog();
                }
            }
        }
    }