Ejemplo n.º 1
0
    public void GetInput()
    {
#if UNITY_EDITOR || UNITY_STANDALONE
        m_horizontalInput = Input.GetAxis("Horizontal");
        m_verticalInput   = Input.GetAxis("Vertical");
#endif

#if UNITY_ANDROID || UNITY_IOS
        float roll = Input.acceleration.x * 2;
        //Debug.Log(roll);

        m_horizontalInput = roll;

        if (stopButton.Pressed())
        {
            brake = -1f;
        }
        else
        {
            brake = 0f;
        }

        if (goButton.Pressed())
        {
            drive = 1f;
        }
        else
        {
            drive = 0f;
        }

        m_verticalInput = brake + drive;
        //m_horizontalInput = Input.GetAxis("Horizontal");
#endif
    }
    public void MoveToTarget()
    {
        //Reverse Camera if "Fire1" is Pressed
        if ((Input.GetButton("Fire2")))
        {
            if ((GameObject.FindGameObjectsWithTag("GoBtn").Length == 1))
            {
                if ((goButton.Pressed()))
                {
                    return;                       //If go button is pressed return.
                }
            }
            if ((GameObject.FindGameObjectsWithTag("StopBtn").Length == 1))
            {
                if ((stopButton.Pressed()))
                {
                    return;                         //If stop button is pressed return.
                }
            }

            Vector3 _targetPos = objectToFollow.position +
                                 objectToFollow.forward * -offset.z +
                                 objectToFollow.right * offset.x +
                                 objectToFollow.up * offset.y;

            transform.position = Vector3.Lerp(transform.position, _targetPos, followSpeed + Time.deltaTime); //Reverse the camera
        }
        else //If the stop buttons don't exist
        {
            Vector3 _targetPos = objectToFollow.position +
                                 objectToFollow.forward * offset.z +
                                 objectToFollow.right * offset.x +
                                 objectToFollow.up * offset.y;

            transform.position = Vector3.Lerp(transform.position, _targetPos, followSpeed + Time.deltaTime); //Follow the vehicle
        }
    }
    private void Update()
    {
        for (int i = 0; i < popUps.Length; i++)
        {
            if (i == popUpIndex)
            {
                popUps[i].SetActive(true);
            }
            else
            {
                popUps[i].SetActive(false);
            }
        }
        if (popUpIndex == 0)
        {
            if (StartButton.Pressed())
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 1)
        {
            if (Input.GetMouseButtonDown(0))
            {
                touchSingle = true;
            }

            if (touchSingle == true)
            {
                if (waitTime <= 0)
                {
                    waitTime = 2f;
                    popUpIndex++;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }
        }
        else if (popUpIndex == 2)
        {
            if (Input.GetButton("Fire2"))
            {
                touchDouble = true;
            }

            if (touchDouble == true)
            {
                if (waitTime <= 0)
                {
                    waitTime = 2f;
                    popUpIndex++;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }
        }
        else if (popUpIndex == 3)
        {
            GoButton.gameObject.SetActive(true);

            if (GoButton.Pressed())
            {
                goPressed = true;
            }

            if (goPressed == true)
            {
                if (waitTime <= 0)
                {
                    waitTime = 2f;
                    popUpIndex++;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }
        }
        else if (popUpIndex == 4)
        {
            StopButton.gameObject.SetActive(true);

            if (StopButton.Pressed())
            {
                stopPressed = true;
            }

            if (stopPressed == true)
            {
                if (waitTime <= 0)
                {
                    waitTime = 2f;
                    popUpIndex++;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }
        }
        else if (popUpIndex == 5)
        {
            if (carController.m_horizontalInput < 0)
            {
                turnRight = true;
            }
            if (carController.m_horizontalInput > 0)
            {
                turnLeft = true;
            }

            if (turnLeft && turnRight)
            {
                if (waitTime <= 0)
                {
                    waitTime = 2f;
                    popUpIndex++;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }
        }
        else if (popUpIndex == 6)
        {
            ResetButton.gameObject.SetActive(true);

            if (ResetButton.Pressed())
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 7)
        {
            if (ContinueButton.Pressed())
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 8)
        {
            GameObject  game        = GameObject.FindWithTag("GameController");
            SignHandler signHandler = game.GetComponent <SignHandler>();
            signHandler.enabled = true;
            // Debug.Log(signSelected);

            if (signSelected == false)
            {
                sign = GameObject.FindWithTag("Sign");
                destructibleController = sign.GetComponent <DestructibleController>();
                signSelected           = true;
            }

            if (destructibleController.thisSignDestroyed == true)
            {
                popUpIndex++;
            }
        }
        else if (popUpIndex == 9)
        {
            ExitButton.gameObject.SetActive(true);
        }
    }