Esempio n. 1
0
    void Update()
    {
        bool go = false;

        if (Input.GetKey(KeyCode.W))
        {
            rigidbody2D.AddForce(move * new Vector2(0, 1) * Time.deltaTime);
            go = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            rigidbody2D.AddForce(move * new Vector2(-1, 0) * Time.deltaTime);
            go = true;
            body.transform.localScale = new Vector3(-1, 1, 1);
        }
        if (Input.GetKey(KeyCode.S))
        {
            rigidbody2D.AddForce(move * new Vector2(0, -1) * Time.deltaTime);
            go = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            rigidbody2D.AddForce(move * new Vector2(1, 0) * Time.deltaTime);
            go = true;
            body.transform.localScale = new Vector3(1, 1, 1);
        }

        if (axe != null)
        {
            axe.transform.position = transform.position;
            axe.GetComponent <Axe>().SetDirection(Director.mousePos - new Vector2(transform.position.x, transform.position.y));
            if (Input.GetMouseButtonDown(0))
            {
                axe.GetComponent <Axe>().Attack();
            }
        }

        if (go)
        {
            time -= Time.deltaTime * 12;
            legs.Go();
        }
        else
        {
            legs.Stop();
        }

        if (Input.GetMouseButtonDown(1))
        {
            health.DrinkPoison();
        }

        if (health.IsDead())
        {
            ReincarnationScript.nextLevel = Application.loadedLevel;
            Application.LoadLevel("Reincarnation");
        }
    }
Esempio n. 2
0
    public void Die()
    {
        AudioSource.PlayClipAtPoint(dieAudio, transform.position);

        deadHeight = transform.position.y - 2f;
        dead       = true;
        time       = 0f;
        legs.Stop();
        //rigidbody2D.
    }
 // Update is called once per frame
 void Update()
 {
     if (heroDetector.IsDetecting() && randomMove)
     {
         randomMovement.StopRandomMovement();
         legs.Go();
         hero       = heroDetector.GetHero();
         randomMove = false;
     }
     else if (!heroDetector.IsDetecting() && !randomMove)
     {
         randomMove = true;
         legs.Stop();
         randomMovement.StartRandomMovement();
     }
     if (!randomMove)
     {
         MoveToHero();
     }
 }
    void Update()
    {
        if (!dead)
        {
            bool go = false;

            if (Input.GetKey(KeyCode.W))
            {
                rigidbody2D.AddForce(move * new Vector2(0, 1) * Time.deltaTime);
                go = true;
            }
            if (Input.GetKey(KeyCode.A))
            {
                rigidbody2D.AddForce(move * new Vector2(-1, 0) * Time.deltaTime);
                go = true;
            }
            if (Input.GetKey(KeyCode.S))
            {
                rigidbody2D.AddForce(move * new Vector2(0, -1) * Time.deltaTime);
                go = true;
            }
            if (Input.GetKey(KeyCode.D))
            {
                rigidbody2D.AddForce(move * new Vector2(1, 0) * Time.deltaTime);
                go = true;
            }

            if (go)
            {
                time -= Time.deltaTime * 12;
                legs.Go();
            }
            else
            {
                legs.Stop();
            }
            axeTime += Time.deltaTime;
            if (axeTime > timeBeforeAxe)
            {
                if (axe == null)
                {
                    axe = Instantiate(axePref, transform.position + Vector3.up * 10f, Quaternion.identity) as GameObject;
                }
                else
                {
                    if (axeTime - timeBeforeAxe < axeFlyTime)
                    {
                        Vector3 newPos = axe.transform.position +
                                         (axeTime - timeBeforeAxe) / axeFlyTime * (transform.position - axe.transform.position) * 5f;

                        axe.transform.Rotate(new Vector3(
                                                 0f, 0f, (axeTime - timeBeforeAxe) * 10f
                                                 ));
                        axe.transform.position = newPos;
                    }
                }
            }
        }
        else
        {
            if (time < deathTime)
            {
                time += Time.deltaTime;
                transform.rotation = new Quaternion(0f, 0f, time / deathTime * 3.14f, 0f);
            }
            deadTotalTime += Time.deltaTime;
            if (deadTotalTime > 3f)
            {
                Application.LoadLevel("Reincarnation");
            }
        }
    }
 public void StopRandomMovement()
 {
     legsScript.Stop();
     go = false;
 }