Exemplo n.º 1
0
 public override IEnumerator TakeDamage(float dmgAmt)
 {
     if (!healthCanvas.isActiveAndEnabled)
     {
         healthCanvas.enabled = true;
     }
     healthStat.CurrentVal -= dmgAmt;
     if (!IsDead)
     {
         MyAnimator.SetTrigger("Damage");
         GameManager.Instance.score += 10;
     }
     else
     {
         MyAnimator.SetTrigger("Die");
         yield return(null);
     }
 }
Exemplo n.º 2
0
    public void HandleLayers()
    {
        if (IsMoving)
        {
            ActivateLayer("Walk");

            MyAnimator.SetFloat("x", direction.x);
            MyAnimator.SetFloat("y", direction.y);
        }
        else if (isAttacking)
        {
            ActivateLayer("Attack");
        }
        else
        {
            ActivateLayer("Idle");
        }
    }
Exemplo n.º 3
0
    public override void Start()
    {
        base.Start();
        if (gm.IsPvp)
        {
            nm = NetworkManager.Instance;
        }

        sr = GetComponent <SpriteRenderer>();
        healthBar.Initialize();
        staminaBar.Initialize();
        boxCol  = GetComponent <BoxCollider2D>();
        sight   = GetComponentInChildren <PlayerSight>();
        myVoice = GetComponent <AudioSource>();

        Dead += (() => MyAnimator.SetTrigger("Dead"));
        Dead += (() => boxCol.enabled = false);
    }
Exemplo n.º 4
0
    private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }
        //if (Jump && MyRigidbody.velocity.y == 0)
        //{
        //    MyRigidbody.AddForce(new Vector2(0, jumpForce));
        //}


        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Exemplo n.º 5
0
    public override void Death()
    {
        fellOff  = false;
        rained   = false;
        time     = 0;
        this.tag = "Enemy";
        MyAnimator.SetTrigger("idle");
        MyAnimator.ResetTrigger("die");
        healthStat.MaxVal     = GameManager.Instance.EnemyHealth;
        healthStat.CurrentVal = healthStat.MaxVal;
        monsterLevel          = GameManager.Instance.EnemyLevel;
        //for when not death
        //healthStat.CurrentVal += 10;
        healthCanvas.enabled = false;
        Target = null;

        transform.position = new Vector3(startPos.x + UnityEngine.Random.Range(2.5f, 6.5f), startPos.y, startPos.z);
    }
Exemplo n.º 6
0
Arquivo: Player.cs Projeto: NZBane/kus
    public virtual void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "SwordCollider")
        {
            health.MyCurrentValue -= 5;
            if (health.MyCurrentValue <= 0)
            {
                Direction = Vector2.zero;

                MyAnimator.SetTrigger("die");

                SceneManager.LoadScene("MainMenu");
                //  Application.Quit(); //works
                //////////////////INSERT GAME OVER SCENE HERE!!!!!!!!!//////////////////////////////(but since enemy is using this, it will also trigger this event when enemy dies)
                //character dies
            }
        }
    }
Exemplo n.º 7
0
    void HandleMovements(float horizontal)
    {
        if (Body.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }

        if (!Attack && !Slide && (OnGround || airControl))
        {
            Body.velocity = new Vector2(horizontal * maxSpeed, Body.velocity.y);
        }
        if (Jump && Body.velocity.y == 0)
        {
            Body.AddForce(new Vector2(0, jumpForce));
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Exemplo n.º 8
0
    /// <summary>
    /// Stops the attack
    /// </summary>
    public void StopAttack()
    {
        SpellBook.MyInstance.StopSpell();

        IsAttacking = false;                       //Makes sure that we are not attacking

        MyAnimator.SetBool("attack", IsAttacking); //Stops the attack animation

        foreach (GearSocket g in gearSockets)
        {
            g.MyAnimator.SetBool("attack", IsAttacking);
        }

        if (attackRoutine != null) //Checks if we have a reference to an co routine
        {
            StopCoroutine(attackRoutine);
        }
    }
Exemplo n.º 9
0
    // Swaps the animator controller for specified one when active as a puppet.
    public void SetAnimatorControllerActive(bool isActive)
    {
        if (isActive)
        {
            if (activatedAnimatorController != null)
            {
                MyAnimator.runtimeAnimatorController = activatedAnimatorController;

                MyAnimator.AnimatorSetDirection(FacingDirection);
            }
        }
        else
        {
            MyAnimator.runtimeAnimatorController = inactiveAnimatorController;

            MyAnimator.AnimatorSetDirection(FacingDirection);
        }
    }
Exemplo n.º 10
0
 private void OnCollisionExit2D(Collision2D other)
 {
     if (other.transform.tag == "SwingingPlatform")
     {
         transform.parent   = null;
         transform.rotation = Quaternion.identity;
         OnGround           = false;
     }
     if (other.transform.tag == "Ground")
     {
         OnGround = false;
     }
     if (other.transform.name == "Catapult_Bowl")
     {
         LaunchPlayer();
         MyAnimator.SetBool("land", true);
     }
 }
Exemplo n.º 11
0
    //METHODS:

    private void HandleMovement(float horizontal) // The horizontal in the parenthesis gets its value from the float Horizontal = blah blah in the fixed update
    {
        if (!Attack && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (Jump && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(horizontal * movementSpeed, jumpForce));
        }
        MyAnimator.SetFloat("Speed", Mathf.Abs(horizontal));

        if (Crouch)
        {
            MyRigidbody.velocity = new Vector2(0, MyRigidbody.velocity.y);
        }
    }
Exemplo n.º 12
0
    private void LookAtTarget()
    {
        if (MyTarget != null)
        {
            Vector2 directionToTarget = (MyTarget.transform.position - transform.position).normalized;

            Vector2 faceing = new Vector2(MyAnimator.GetFloat("x"), MyAnimator.GetFloat("y"));

            float angleToTarget = Vector2.Angle(faceing, directionToTarget);

            if (angleToTarget > fieldOfView / 2)
            {
                MyAnimator.SetFloat("x", directionToTarget.x);
                MyAnimator.SetFloat("y", directionToTarget.y);

                updateDirection = true;
            }
        }
    }
Exemplo n.º 13
0
    public void ToGrab()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (!grabbed)
            {
                Physics2D.queriesStartInColliders = false;
                hit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, distance);

                if (hit.collider != null && hit.collider.tag == "Pick Up")
                {
                    grabbed = true;

                    hit.transform.SetParent(this.transform, true);

                    MyAnimator.SetTrigger("pickup");
                    MyAnimator.SetBool("carry", true);
                    MyAnimator.ResetTrigger("throw");
                }
            }
            else if (Physics2D.OverlapPoint(holdpoint.position, notgrabbed))
            {
                grabbed = false;

                if (hit.collider.gameObject.GetComponent <Rigidbody2D>() != null)
                {
                    hit.rigidbody.isKinematic = false;
                    hit.collider.isTrigger    = false;

                    hit.transform.parent = null;

                    hit.collider.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(transform.localScale.x, 1) * throwforce;
                    MyAnimator.SetTrigger("throw");
                    MyAnimator.SetBool("carry", false);
                }
            }

            if (grabbed)
            {
                hit.collider.gameObject.transform.position = holdpoint.position;
            }
        }
    }
Exemplo n.º 14
0
    private void HandleInputs()
    {
        if (Input.GetButtonDown("Jump"))
        {
            MyAnimator.SetTrigger("jump");
        }
        else if (Input.GetButtonUp("Jump"))
        {
            if (rb2d.velocity.y > 0)
            {
                rb2d.velocity = new Vector2(rb2d.velocity.x, rb2d.velocity.y * 0.5f);
            }
        }

        if (Input.GetButtonDown("Fire1"))
        {
            MyAnimator.SetTrigger("attack");
        }
    }
Exemplo n.º 15
0
 //Handle player inputs and it animations
 private void handleInput()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         MyAnimator.SetTrigger("jump");
     }
     if (Input.GetKeyDown(KeyCode.L))
     {
         MyAnimator.SetTrigger("attack");
     }
     if (Input.GetKeyDown(KeyCode.K))
     {
         MyAnimator.SetTrigger("slide");
     }
     if (Input.GetKeyDown(KeyCode.P))
     {
         MyAnimator.SetTrigger("shoot");
     }
 }
Exemplo n.º 16
0
 private void HandleInput()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         MyAnimator.SetTrigger("jump");
     }
     if (Input.GetKeyDown(KeyCode.LeftShift))
     {
         MyAnimator.SetTrigger("attack");
     }
     //if(Input.GetKeyDown(KeyCode.LeftControl)){
     //	MyAnimator.SetTrigger ("slide");
     //}
     if (Input.GetKeyDown(KeyCode.V))
     {
         MyAnimator.SetTrigger("throw");
         ThrowKnife(0);
     }
 }
Exemplo n.º 17
0
 public override IEnumerator TakeDamage()
 {
     health -= 10;
     if (!IsDead)
     {
         MyAnimator.SetTrigger("Damage");
     }
     else
     {
         MyAnimator.SetTrigger("Death");
         if (health == 0)
         {
             gameMenuController.SetLifeImages();
             StartCoroutine("Respawn");
         }
         health = 50;
     }
     yield return(null);
 }
Exemplo n.º 18
0
    protected new void Awake()
    {
        base.Awake();
        _coll  = GetComponent <PolygonCollider2D>();
        _rend  = GetComponent <SpriteRenderer>();
        _anim  = GetComponent <MyAnimator>();
        _audio = GetComponent <MyAudioSource>();

        _coll.enabled = false;
        _rend.enabled = false;
        enabled       = false;

        PushingSmallState s1 = new PushingSmallState(_ASM, this);
        PushingBigState   s2 = new PushingBigState(_ASM, this);

        s1.SetTargetStates(s2);

        _ASM.InitializeWithStates(new InactiveBaseAttackState(_ASM), s1);
    }
Exemplo n.º 19
0
 public virtual void Move(Vector2 dir)
 {
     if (!Moveable)
     {
         return;
     }
     movingDir = dir.normalized;
     if (dir.magnitude < 0.01f)
     {
         isMoving             = false;
         MyRigidbody.velocity = Vector3.zero;
         MyAnimator.SetBool("isMoving", false);
     }
     else
     {
         isMoving = true;
         MyAnimator.SetBool("isMoving", true);
     }
 }
Exemplo n.º 20
0
 // This is a function for player movement
 private void HandleMovement(float horizontal)
 {
     // If we are falling then start the landing animation
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);
     }
     // Horizontal movement
     if (!Attack && !Slide && (OnGround || airControl))
     {
         MyRigidbody.velocity = new Vector2(movementSpeed * horizontal, MyRigidbody.velocity.y);
     }
     if (Jump && MyRigidbody.velocity.y == 0)
     {
         MyRigidbody.AddForce(new Vector2(0, jumpForce));
     }
     // Set the speed in the Animator
     MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
 }
Exemplo n.º 21
0
    void Start( )
    {
        if (useLivesOnly)
        {
            maxHealth      = 1.0f;
            startingHealth = 1.0f;
        }
        if (this.tag == "Enemy")
        {
            anim = GetComponent <MyAnimator> ();
        }
        currentHealth = startingHealth;
        GameObject obj = GameObject.FindWithTag("GameController");

        gameController = obj.GetComponent <WinLoseMessage> ();
        GameObject model = GameObject.FindWithTag("Animated");

        charAnim = model.GetComponent <CharAnim> ();
    }
Exemplo n.º 22
0
 // проверка на нажатие клавиш и запуск анимации
 private void HandleInput()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         MyAnimator.SetTrigger("jump");
     }
     if (Input.GetKeyDown(KeyCode.LeftControl))
     {
         MyAnimator.SetTrigger("slide");
     }
     if (Input.GetKeyDown(KeyCode.Keypad4))
     {
         MyAnimator.SetTrigger("attack");
     }
     if (Input.GetKeyDown(KeyCode.Keypad5) && !Die)
     {
         MyAnimator.SetTrigger("shoot");
     }
 }
Exemplo n.º 23
0
    public void Move()
    {
        if (rightEdge == null)
        {
            MyAnimator.SetFloat("speed", 1);

            transform.Translate(GetDirection() * (maxSpeed * Time.deltaTime));
        }
        else if ((GetDirection().x > 0 && transform.position.x < rightEdge.position.x) || (GetDirection().x < 0 && transform.position.x > leftEdge.position.x))
        {
            MyAnimator.SetFloat("speed", 1);

            transform.Translate(GetDirection() * (maxSpeed * Time.deltaTime));
        }
        else if (currentState is PatrolState)
        {
            ChangeDirection();
        }
    }
Exemplo n.º 24
0
    public void Move()
    {
        if (!Attack)
        {
            if (transform.right.x > 0 && transform.position.x < rightEdge.position.x || transform.right.x < 0 && transform.position.x > leftEdge.position.x)
            //if (GetDirection().x > 0 && transform.position.x < rightEdge.position.x || GetDirection().x < 0 && transform.position.x > leftEdge.position.x)
            {
                MyAnimator.SetFloat("speed", 1);

                transform.Translate(transform.right * movementSpeed * Time.deltaTime);

                //transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime));
            }
            else if (currentState is PatrolState)
            {
                ChangeDirection();
            }
        }
    }
Exemplo n.º 25
0
    protected virtual void Move()                                    // 몬스터 이동
    {
        if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk")) // 이동
        {
            if (transform.localScale.x >= 1)                         // 오른쪽 보고있을때
            {
                transform.Translate(transform.right * MonsterSpeed * Time.deltaTime, Space.World);
            }
            else // 왼쪽 보고있을때
            {
                transform.Translate(-transform.right * MonsterSpeed * Time.deltaTime, Space.World);
            }
        }

        if (MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("NoMove"))
        {
            transform.Translate(Vector2.zero, Space.World);
        }
    }
Exemplo n.º 26
0
 private void handleImput()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         if (IsGrounded())
         {
             MyAnimator.SetTrigger("attack");
         }
     }
     if (Input.GetKeyDown(KeyCode.LeftControl))
     {
         MyAnimator.SetTrigger("slide");
     }
     if (Input.GetKeyDown(KeyCode.Space) && !IsFalling)
     {
         onAir = true;
         MyAnimator.SetTrigger("jump");
     }
 }
Exemplo n.º 27
0
 private void HandleInput()
 {
     if (Input.GetKeyDown(KeyCode.LeftShift))
     {
         MyAnimator.SetTrigger("attack");
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         MyAnimator.SetTrigger("slide");
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         MyAnimator.SetTrigger("jump");
     }
     if (Input.GetKeyDown(KeyCode.F))
     {
         MyAnimator.SetTrigger("throw");
     }
 }
Exemplo n.º 28
0
    public void Move()
    {
        MyAnimator.SetFloat("speed", 1);

        transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime));

        if (facingRight)
        {
            Vector3 scale = transform.localScale;
            scale.x = 1;
            transform.localScale = scale;
        }
        if (!facingRight)
        {
            Vector3 scale = transform.localScale;
            scale.x = -1;
            transform.localScale = scale;
        }
    }
Exemplo n.º 29
0
 private void HandleInput() // Verifica apasarea unor taste care activeaza triggere care activeaza aniamatii -> altceva
 {
     if (Input.GetKeyDown(KeyCode.X))
     {
         MyAnimator.SetTrigger("attack");
     }
     if (Input.GetKeyDown(KeyCode.Z))
     {
         MyAnimator.SetTrigger("throw");
     }
     if (Input.GetKeyDown(KeyCode.UpArrow))
     {
         MyAnimator.SetTrigger("jump");
     }
     if (Input.GetKeyDown(KeyCode.DownArrow) && OnGround)
     {
         MyAnimator.SetTrigger("slide");
     }
 }
Exemplo n.º 30
0
    public override IEnumerator TakeDamage()
    {
        if (!healthCanvas.isActiveAndEnabled)
        {
            healthCanvas.enabled = true;
        }

        healthStat.CurrentValue -= 10;

        if (!IsDead)
        {
            MyAnimator.SetTrigger("damage");
        }
        else
        {
            MyAnimator.SetTrigger("die");
            yield return(null);
        }
    }