public void MoveHorizontal(float Playspeed)
    {
        rb.velocity = new Vector2(Playspeed, rb.velocity.y);

        if (Playspeed < 0)
        {
            SRflip.flipX = true;
            if (Input.GetKey(KeyCode.LeftControl))
            {
                speedPlayer = 3;
                Debug.Log(speedPlayer);
            }
            else
            {
                speedPlayer = speedPlayer;
            }
        }
        if (Playspeed > 0)
        {
            SRflip.flipX = false;
            if (Input.GetKey(KeyCode.LeftControl))
            {
                speedPlayer = 3;
                Debug.Log(speedPlayer);
            }
            else
            {
                speedPlayer = speedPlayer;
            }
        }
        anim.SetInteger("condition", 1);
        SoundFXCtrl.PlaySound("PlayerWalking");
    }
    void Update()
    {
        float Playspeed = Input.GetAxisRaw("Horizontal");

        Playspeed *= speedPlayer;

        if (Playspeed != 0)
        {
            MoveHorizontal(Playspeed);
        }
        else
        {
            Movestop();
        }

        if (IsGrounded() && Input.GetKeyDown(KeyCode.Space))
        {
            rb.velocity = Vector2.up * jumpingHight;
            anim.Play("Player_Jump");
            SoundFXCtrl.PlaySound("PlayerJumping");
        }

        if (hiding == true)
        {
            gameObject.layer = LayerMask.NameToLayer("HidableOBJ");
            hidingPlayer.SetActive(false);
            Debug.Log("You are Hiding behind Box");
        }
        else
        {
            hidingPlayer.SetActive(true);
            //PLAYER.layer = 2;
            Debug.Log("You are not hiding");
        }

        if (PlayerIsDead == true)
        {
            SoundFXCtrl.PlaySound("PlayerDie");
            StartCoroutine(SetDelayDead());
            anim.Play("Player_Dead");
            speedPlayer = 0;
            Debug.Log("Player is dead");
        }

        if (Input.GetKeyDown(KeyCode.Escape)) //pause the game
        {
            if (GameIsPause)
            {
                Resume();
            }
            else
            {
                Pause();
            }
        }
    }
Exemplo n.º 3
0
 // Use this for initialization
 void Awake()
 {
     audioSource       = audio;
     sequenceResetTime = sequenceReset;
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 4
0
    private void Update()
    {
        transform.Translate(Vector2.right * speed * Time.deltaTime);

        RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector2.down, distance);

        if (groundInfo.collider == false)
        {
            //enemy running
            if (movingRight == true)
            {
                enemyAnim.SetInteger("EnemyCondition", 1);
                transform.eulerAngles = new Vector3(0, -180, 0);
                movingRight           = false;
            }
            else
            {
                enemyAnim.SetInteger("EnemyCondition", 1);
                transform.eulerAngles = new Vector3(0, 0, 0);
                movingRight           = true;
            }
        }

        if (Attacking == true)
        {
            speed = 0;
            enemyAnim.SetInteger("EnemyCondition", 3);
            RunningRange.SetActive(false);
            SoundFXCtrl.PlaySound("EnemyAttacking");
            Debug.Log("Enemy attacking!!!");
        }
        else
        {
            RunningRange.SetActive(true);
        }

        if (Running == true)
        {
            speed = 3;
            SoundFXCtrl.PlaySound("EnemyRunning");
            SoundFXCtrl.PlaySound("EnemyScream");
            enemyAnim.SetInteger("EnemyCondition", 2);
        }

        /*else
         * {
         *  Walking = true;
         * }*/

        if (Walking == true)
        {
            speed = 1;
            enemyAnim.SetInteger("EnemyCondition", 1);
            SoundFXCtrl.PlaySound("EnemyWalking");
        }

        /*else
         * {
         *  speed = 0;
         *  enemyAnim.SetInteger("EnemyCondition", 0);
         * }*/

        if (Idle == true)
        {
            speed = 0;
            enemyAnim.SetInteger("EnemyCondition", 0);
        }
    }
 // Use this for initialization
 void Awake()
 {
     instance    = this;
     audioSource = audio;
 }