Hunter.Update C# (CSharp) Method

Update() public method

public Update ( ) : void
return void
    void Update()
    {
        /*
        if (anim.GetCurrentAnimatorStateInfo(0).IsName("HunterWalk") && speed == 0)
        {
            speed = defaultSpeed;
        }
        */
        // initialize the position of the linecast
        startCast = endCast = gameObject.transform.position ;

        counter *= Time.deltaTime;

        // movement of monster and changes the position of linecast
        if (facingRight)     // face right
        {
            movement = speed * Time.deltaTime;
            transform.Translate(movement, 0, 0);
            endCast.x += lineCastDistance;
            startCast.y -= heightOffset;
            endCast.y -= heightOffset;
            fogLeft.SetActive(true);
            fogRight.SetActive(false);
        }
        else                // face left
        {
            movement = speed * Time.deltaTime;
            transform.Translate(-movement, 0, 0);
            endCast.x -= lineCastDistance;
            startCast.y -= heightOffset;
            endCast.y -= heightOffset;
            fogLeft.SetActive(false);
            fogRight.SetActive(true);
        }

        if (gameObject.transform.position.x < leftEndPath
            || gameObject.transform.position.x > rightEndPath)
        {
            FlipEnemy();
        }

        // Visually see the line cast in scene mode, NOT GAME
        Debug.DrawLine(startCast, endCast, Color.magenta);

        /////
        RaycastHit2D[] EnemyVisionTrigger;
        EnemyVisionTrigger = Physics2D.LinecastAll(startCast, endCast);

        for (int i = 0; i < EnemyVisionTrigger.Length; i++)
        {
            RaycastHit2D hit = EnemyVisionTrigger[i];
            if (hit.collider && hit.collider.tag == "Player" && !player.hide)
            {
                isCaught = true;
                //freeze player
                player.normalSpeed = 0;
                // spottedCue.SetActive(true);  // BUGGED NULL REFERENCE
                // this code runs when player is seen

            }
        }
        // Making the line cast
        // RaycastHit2D EnemyVisionTrigger = Physics2D.Linecast(startCast, endCast);

        // check if the collider exists and if the collider is the player
           // Debug.Log(speed);
        if (isCaught == true && killPlayer == false)
        {

            ///speed = activeSpeed;

            //Tests which direction the monster is facing
            if (facingRight)
            {
                //Multiply the movement by the amount set in the inspector
                transform.Translate(movement * activeSpeed, 0, 0);
            }
            else
            {
                //Multiply the movement by the amount set in the inspector
                transform.Translate(-movement * activeSpeed, 0, 0);
            }

        }
        /*
        else if(killPlayer == false)
        {
            speed = defaultSpeed;
        }
        */

        // Proximity camera shake

        // Update player distance
        playerDistance.x = player.transform.position.x - gameObject.transform.position.x;
        playerDistance.y = player.transform.position.y - gameObject.transform.position.y;

        // Make the values positive for calculation
        if (playerDistance.x < 0)
            playerDistance.x = -playerDistance.x;
        if (playerDistance.y < 0)
            playerDistance.y = -playerDistance.y;
    }

Usage Example

Example #1
0
    public void Update()
    {
//		if (!Active)
//		{
//			return;
//		}

        HandleKeyboard();

        // HACK -- this shouldn't be handled regardless, but has to in order to complete animations
        m_hunter.Update();

        if (m_enabled)
        {
            m_hunter.RunSpeed = hunterSpeed;
            UpdateTreats();

            m_player.Update();
            m_hunter.Update();

            if (DidHunterFindPlayer())
            {
                m_effectSource.clip = m_gotchaEffect;
                m_effectSource.Play();
                Disable();
            }

            DetectCollisions();
        }
        else if (ReadyToExit())
        {
            Cleanup();
            m_parent.MoveToState(StateMachine.State.GameOver);
        }
    }
All Usage Examples Of Hunter::Update