Example #1
0
    void Update()
    {
        m_animator.SetBool("Grounded", true);

        //atStart = this.transform.position;
        float v = Input.GetAxis("Vertical") * (-1) + joystick.Vertical * (-1);
        float h = Input.GetAxis("Horizontal") * (-1) + joystick.Horizontal * (-1);


        m_currentV = Mathf.Lerp(m_currentV, v, Time.deltaTime * m_interpolation);
        m_currentH = Mathf.Lerp(m_currentH, h, Time.deltaTime * m_interpolation);

        Vector3 direction = new Vector3(m_currentH, 0, m_currentV);

        float directionLength = direction.magnitude;

        direction.y = 0;
        direction   = direction.normalized * directionLength;

        if (direction != Vector3.zero)
        {
            m_currentDirection = Vector3.Slerp(m_currentDirection, direction, Time.deltaTime * m_interpolation);


            transform.rotation             = Quaternion.LookRotation(m_currentDirection);
            transform.position            += m_currentDirection * m_moveSpeed * Time.deltaTime;
            atStart                        = this.transform.position - atStart;
            Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, this.transform.position.z + 5.6f);
            //Camera.main.transform.rotation =  Quaternion.Euler(new Vector3 (47f, 354.255f, 0));

            m_animator.SetFloat("MoveSpeed", direction.magnitude);
        }



        if (buttonSpace.Pressed || Input.GetKeyDown("space"))           //choosing place for mark
        {
            musicSource.clip = planeClip;
            musicSource.Play();
            Destroy(plane);                                                                                                             //delete lasp plane
            Ray        ray = new Ray(new Vector3(this.transform.position.x, 0.99f, this.transform.position.z), new Vector3(0, -1f, 0)); //checkong floor under
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject;
                PlatformLength platform  = hitObject.GetComponent <PlatformLength> ();
                if (platform != null)
                {
                    Debug.Log("14645");
                    //Instantiate (plane, new Vector3 (Mathf.Round(this.transform.position.x),0.99f,Mathf.Round(this.transform.position.z)), Quaternion.identity);
                    plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
                    plane.transform.localScale = new Vector3(0.1f, 1f, 0.1f);
                    plane.GetComponent <Renderer>().material.color = Color.blue;
                    plane.transform.position = new Vector3(Mathf.Round(this.transform.position.x), 0.99f, Mathf.Round(this.transform.position.z));
                }
            }
            buttonSpace.endSpace();
        }

        if ((buttonQ.Pressed || Input.GetKeyDown("q")) && plane != null)             // desroying marked place
        {
            plane.GetComponent <Renderer>().material.color = Color.red;
            if (CreatingLevel.timer < 0)
            {
                Destroy(plane);
            }
            else
            {
                StartCoroutine(ReactPlane(plane));
            }
            buttonQ.endQ();
        }


        if ((buttonE.Pressed || Input.GetKeyDown("e")) && spheres.Count != 0)             //bombing sphere
        {
            int j = spheres.Count;
            for (int i = 0; i < j; i++)
            {
                StartCoroutine(ReactSphere(spheres[i]));
            }
            buttonE.endE();
        }

        if (this.transform.position.y < -20)
        {
            CubeMove.destroyedCubes   = 0;
            CubeMove.destroyedMistake = 0;
            CubeMove.blackFallen      = 0;
            CubeMove.countAudio       = 0;
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
        }
    }
Example #2
0
    void Update()
    {
        float   deltaX   = Input.GetAxis("Horizontal") * speed * (-1) + joystick.Horizontal * speed * (-1);
        float   deltaZ   = Input.GetAxis("Vertical") * speed * (-1) + joystick.Vertical * speed * (-1);
        Vector3 movement = new Vector3(deltaX, 0, deltaZ);

        movement   = Vector3.ClampMagnitude(movement, speed);       //limiting speed
        movement.y = gravity;

        movement *= Time.deltaTime;
        movement  = transform.TransformDirection(movement);         //from local to global
        _charController.Move(movement);


        if (buttonSpace.Pressed || Input.GetKeyDown("space"))           //choosing place for mark
        {
            musicSource.clip = planeClip;
            musicSource.Play();
            Destroy(plane);                                                            //delete lasp plane
            Ray        ray = new Ray(this.transform.position, new Vector3(0, -1f, 0)); //checkong floor under
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject     hitObject = hit.transform.gameObject;
                PlatformLength platform  = hitObject.GetComponent <PlatformLength> ();
                if (platform != null)
                {
                    //Instantiate (plane, new Vector3 (Mathf.Round(this.transform.position.x),0.99f,Mathf.Round(this.transform.position.z)), Quaternion.identity);
                    plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
                    plane.transform.localScale = new Vector3(0.1f, 1f, 0.1f);
                    plane.GetComponent <Renderer>().material.color = Color.blue;
                    plane.transform.position = new Vector3(Mathf.Round(this.transform.position.x), 0.99f, Mathf.Round(this.transform.position.z));
                }
            }
            buttonSpace.endSpace();
        }

        if ((buttonQ.Pressed || Input.GetKeyDown("q")) && plane != null)             // desroying marked place
        {
            plane.GetComponent <Renderer>().material.color = Color.red;
            if (CreatingLevel.timer < 0)
            {
                Destroy(plane);
            }
            else
            {
                StartCoroutine(ReactPlane(plane));
            }
            buttonQ.endQ();
        }


        if ((buttonE.Pressed || Input.GetKeyDown("e")) && spheres.Count != 0)             //bombing sphere
        {
            int j = spheres.Count;
            for (int i = 0; i < j; i++)
            {
                StartCoroutine(ReactSphere(spheres[i]));
            }
            buttonE.endE();
        }

        if (this.transform.position.y < -20)
        {
            CubeMove.destroyedCubes   = 0;
            CubeMove.destroyedMistake = 0;
            CubeMove.blackFallen      = 0;
            CubeMove.countAudio       = 0;
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
        }
    }