Exemple #1
0
    void Start()
    {
        gm        = GameObject.FindGameObjectWithTag("GameController").GetComponent <DataPersistance>();
        mat.color = new Color(1.0f, 1.0f, 1.0f);

        if (gm.firstTimeLoading == false)
        {
            health = gm.getPlayerHealth();
        }
        else
        {
            health = 3;
            gm.setPlayerScore(0);
            gm.firstTimeLoading = false;
        }

        gm.setPlayerHealth(health);

        gameOver  = gameObject.GetComponent <SceneController>();
        uiManager = UI.GetComponent <UI_Manager>();
        PlayerPrefs.SetInt("HighScore", 0);
    }
Exemple #2
0
    void Update()
    {
        gm.setPlayerHealth(health);

        if (health > 0)
        {
            controllerPos.x = Input.GetAxis("Horizontal_1") * Time.deltaTime * RotateSpeed;
            controllerPos.z = Input.GetAxis("Vertical_1") * Time.deltaTime * RotateSpeed;
        }


        //controllerPos.Normalize();

        if (Input.GetButton("X_1"))
        {
            // anim.SetBool("Attack", true);
        }
        else
        {
            //anim.SetBool("Attack", false);
        }

        //anim.SetFloat("Horizontal", controllerPos.x);
        //anim.SetFloat("Vertical", controllerPos.z);

        if (controllerPos.z > 0.009f)
        {
            //Debug.Log("running");
            //when player is moving
            anim.SetBool("RunningBackwards", false);
            anim.SetBool("Running", true);
            current_delay -= 1 * Time.deltaTime;
            if (current_delay <= 0.0f)
            {
                audio.Play();
                current_delay = footstep_delay;
            }
        }
        else if (controllerPos.z < -0.01f)
        {
            anim.SetBool("Running", true);
            current_delay -= 1 * Time.deltaTime;
            if (current_delay <= 0.0f)
            {
                audio.Play();
                current_delay = footstep_delay;
            }
            anim.SetBool("RunningBackwards", true);
        }
        else if (controllerPos.z == 0)
        {
            anim.SetBool("RunningBackwards", false);
            //comes to a stop
            anim.SetBool("Running", false);
        }

        if (health <= 0)
        {
            PlayerPrefs.SetInt("HighScore", uiManager.EggCount);
            anim.SetBool("Death", true);
            gm.FlushData();
            //gameOver.GameOver();
            StartCoroutine(endGame());
        }

        //anim.SetFloat("Horizontal", (x * 10));
        //anim.SetFloat("Vertical", (z * 10));
        //transform.Rotate(0, controllerPos.x , 0);
        // transform.Translate(0, 0, controllerPos.z);
        // healthRef.Health = 3;
        if (health > 0)
        {
            GameObject camera = GameObject.FindGameObjectWithTag("MainCamera");
            transform.position     += camera.transform.forward * controllerPos.z;
            transform.localRotation = camera.transform.localRotation;
        }
        // transform.LookAt(camera.transform.localRotation.eulerAngles);

        //transform.Translate(transform.position + camera.transform.forward * controllerPos.z);
        //transform.Rotate(0, camera.transform.rotation.x, 0);

        if (hit)
        {
            mat.color = new Color(1.0f, 0, 0);
            timer    += 1.0f * Time.deltaTime;

            if (timer >= 1.0f)
            {
                mat.color = new Color(1.0f, 1.0f, 1.0f);
                timer     = 0;
                hit       = false;
            }
        }
    }