Beispiel #1
0
 public void wither()
 {
     tree.changeHP(20f);
     //GetComponent<SpriteRenderer>().color = new Color(1f, 0.7685f, 0.5058f);
     GetComponent <SpriteRenderer>().DOColor(new Color(1f, 0.7685f, 0.5058f), 0.2f);
     iswither = true;
 }
Beispiel #2
0
    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    void Update()
    {
        if (Value < 0 || freq == 0)
        {
            return;
        }

        _time  += Time.deltaTime;
        _total += Time.deltaTime;

        if (type == toolType.Fire)
        {
            float t = y0 + amplitude * Mathf.Sin(speed * Time.time);
            transform.localScale = new Vector3(t, t, t);
        }

        if (_time >= freq)
        {
            _time -= freq;
            tree.changeHP(Value);
            if (particleSystem != null)
            {
                particleSystem.Play();
            }
        }
        if (_total >= lifeTime)
        {
            Destroy(gameObject);
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (animator != null)
        {
            animator.SetFloat("Speed", Mathf.Abs(player.velocity.x));
        }

        if (stateController.state.state != GameManager.State.Running)
        {
            return;
        }

        if (tool != null)
        {
            icon.SetActive(true);
        }
        else
        {
            icon.SetActive(false);
        }

        if (isClimbing && Input.GetKey(keyClimb))
        {
            player.AddForce(Vector2.up * GetMoveParameter(MoveParameter.CLIMB), ForceMode2D.Force);
        }
        else
        {
            if (Input.GetKeyDown(keyAttack) && tool != null)
            {
                if (type == Player.characterType.Attack)
                {
                    if (tool.GetComponent <Tool>().type == Tool.toolType.Pesticide && onLeaf)
                    {
                        Instantiate(tool, transform.position - Vector3.up * 0.3f, Quaternion.identity);
                        tool = null;

                        leaf.wither();
                    }
                    else if (tool.GetComponent <Tool>().type != Tool.toolType.Pesticide)
                    {
                        RaycastHit2D h = Physics2D.Raycast(player.transform.position, -Vector3.right * transform.localScale.x, 0.8f, 1 << LayerMask.NameToLayer("Tree"));
                        if (h.collider != null)
                        {
                            tree.changeHP(tool.GetComponent <Tool>().Value < 0 ? tool.GetComponent <Tool>().Value : 0);
                            Instantiate(tool, h.point, Quaternion.identity);
                            soundManager.audiosource.PlayOneShot(soundManager.UseItem);
                            tool = null;
                        }
                    }
                }
                else
                {
                    if (tool.GetComponent <Tool>().type == Tool.toolType.Pesticide && onLeaf && leaf.iswither)
                    {
                        Instantiate(tool, transform.position - Vector3.up * 0.3f, Quaternion.identity);
                        tool = null;

                        leaf.recover();
                    }
                    else if (tool.GetComponent <Tool>().type != Tool.toolType.Pesticide)
                    {
                        RaycastHit2D h = Physics2D.Raycast(player.transform.position, -Vector3.right * transform.localScale.x, 0.8f, 1 << LayerMask.NameToLayer("Cancer"));
                        if (h.collider != null && h.collider.gameObject.GetComponent <Tool>().type == tool.GetComponent <Tool>().type)
                        {
                            tree.changeHP(tool.GetComponent <Tool>().Value);
                            Instantiate(tool, h.point, Quaternion.identity);
                            Destroy(h.transform.gameObject);
                            soundManager.audiosource.PlayOneShot(soundManager.UseItem);
                            tool = null;
                        }
                    }
                }
            }

            if (Input.GetKey(keyLeft) && !isJumping)
            {
                transform.localScale = new Vector3(1, 1, 1);
                player.velocity      = new Vector3(-4f, player.velocity.y, 0f);
                //if(player.velocity.x <= 6f)
                //    player.AddForce(Vector2.left * GetMoveParameter(MoveParameter.RUN), ForceMode2D.Impulse);
            }
            else if (Input.GetKey(keyRight) && !isJumping)
            {
                transform.localScale = new Vector3(-1, 1, 1);
                player.velocity      = new Vector3(4f, player.velocity.y, 0f);
                //if(player.velocity.x <= 6f)
                //    player.AddForce(Vector2.right * GetMoveParameter(MoveParameter.RUN), ForceMode2D.Impulse);
            }
            else
            {
                //player.velocity = new Vector2(0 ,player.velocity.y);
            }

            if (Input.GetKeyDown(keyJump) && !isJumping)
            {
                player.velocity = Vector2.up * 8f;
            }

            if (Input.GetKeyUp(keyJump))
            {
                soundManager.audiosource.PlayOneShot(soundManager.JumpSFX);
                isJumping = true;
            }

            RaycastHit2D hit  = Physics2D.Raycast(player.transform.position - Vector3.up * 0.8f, -Vector2.up, 0.1f);
            RaycastHit2D hit1 = Physics2D.Raycast(player.transform.position - Vector3.up * 0.8f - Vector3.right * 0.2f, -Vector2.up, 0.1f);
            RaycastHit2D hit2 = Physics2D.Raycast(player.transform.position - Vector3.up * 0.8f + Vector3.right * 0.2f, -Vector2.up, 0.1f);
            if ((hit.collider != null || hit1.collider != null || hit2.collider != null) && isJumping)
            {
                isJumping = false;
            }

            if (player.velocity.y < 0)
            {
                player.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
            }
            else if (player.velocity.y > 0 && !Input.GetKey(keyJump))
            {
                player.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
            }
        }
    }