Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        ammount.text = PunktyDoWydania.ToString();
        EXP.value    = currentexp;
        if ((Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) && (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) || (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) && (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) ||
            (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) && (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) || (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) && (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)))
        {
            speed = diagonalspeed;
        }
        else
        {
            speed = 3 + (Agility * 0.4f);
        }
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
        {
            transform.Translate(new Vector3(speed * Time.deltaTime, 0), Space.World);
        }
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            transform.Translate(new Vector3(0, speed * Time.deltaTime), Space.World);
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
        {
            transform.Translate(new Vector3(0, -speed * Time.deltaTime), Space.World);
        }
        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            transform.Translate(new Vector3(-speed * Time.deltaTime, 0), Space.World);
        }
        if (Input.GetKey(KeyCode.Mouse0) && timestamp <= Time.time && Time.timeScale > 0.5f)
        {
            timestamp = Time.time + CurrentWeapon.givecooldown();

            Vector2 mousepos = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
            Vector2 mypos    = transform.position;
            Vector2 dir      = mousepos - mypos;
            dir.Normalize();
            CurrentWeapon.Shoot(dir, mypos);
        }
        Vector2 mousepos1 = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
        Vector2 posi      = transform.position;
        var     dir1      = mousepos1 - posi;
        var     angle     = Mathf.Atan2(dir1.y, dir1.x) * Mathf.Rad2Deg;

        transform.rotation = Quaternion.AngleAxis(angle + 90, Vector3.forward);
        if (currenthealth == 0 && isDead == false)
        {
            isDead         = true;
            Time.timeScale = 0f;
            GetComponent <AudioSource>().PlayOneShot(turnedzombie);
            LosingCanvas.enabled = true;
        }
        if (immortalafterbite == true)
        {
            if (loweringimmortality == false)
            {
                if (currenthealth != 0)
                {
                    GetComponent <AudioSource>().PlayOneShot(hatysz);
                    StartCoroutine(FadeImage(true));
                }
                timestampGotHit     = Time.time + gothitcooldown;
                loweringimmortality = true;
            }
            if (timestampGotHit > Time.time)
            {
                if (loweringAnimImmort)
                {
                    timestampblink     = Time.time + gothitanimfrequency;
                    loweringAnimImmort = false;
                }
                if (timestampblink > Time.time)
                {
                    GetComponent <SpriteRenderer>().color = new Color(0f, 0f, 0f, 1f);
                }
                else if (timestampblink + gothitanimfrequency > Time.time)
                {
                    GetComponent <SpriteRenderer>().color = original;
                }
                else
                {
                    loweringAnimImmort = true;
                }
            }
            else
            {
                GetComponent <SpriteRenderer>().color = original;
                immortalafterbite   = false;
                loweringimmortality = false;
                loweringAnimImmort  = false;
            }
        }
        if (currenthealth == 0)
        {
            GetComponent <SpriteRenderer>().color = new Color(0.3f, 0.8f, 0.3f, 1f);
        }
        if (currentexp == nextlevelexp)
        {
            GetComponent <AudioSource>().PlayOneShot(Advance_snd);
            Level++;
            lvl.text = Level.ToString();
            PunktyDoWydania++;
            currentexp    = 0;
            nextlevelexp += 50;
            EXP.maxValue  = nextlevelexp;
            if (PunktyDoWydania > 0)
            {
                AdvanceInfo.enabled = true;
            }
            else
            {
                AdvanceInfo.enabled = false;
            }
        }
        if (PunktyDoWydania > 0 && Input.GetKey(KeyCode.Space) && !isDead)
        {
            Awans.enabled  = true;
            Time.timeScale = 0.05f;
        }
    }