示例#1
0
    private void MobileUpdate()
    {
        //CoolDown management
        if (coolDownAccumulated < playerSettings.GetCoolDownTime())
        {
            coolDownAccumulated += Time.deltaTime;
        }

        if (Input.touchCount == 1)
        {
            int fingerID = Input.GetTouch(0).fingerId;
            if (!buttonPressed.IsButtonPressed() && Input.GetTouch(0).phase == TouchPhase.Ended && !IsPointerOverUIObject())
            {
                Vector3 raycastHit = getRayCastPoint(Input.GetTouch(0).position);
                if (raycastHit != Vector3.zero)
                {
                    if (dashed && touchStartPosition != null && IsDashLongEnough(Input.GetTouch(0).position))
                    {
                        Debug.Log("DASH");
                        navMeshAgent.destination = Flash(raycastHit);
                        return;
                    }
                    else
                    {
                        navMeshAgent.destination = raycastHit;
                        navMeshAgent.isStopped   = false;
                    }
                }

                dashed             = false;
                touchStartPosition = null;
            }
            else if (Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                Debug.Log("MOVED");
                dashed = true;
            }
            else if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                touchStartPosition = Input.GetTouch(0).position;
            }
            else
            {
                //Debug.Log("NO HACER NADA");
            }
        }
        else if (Input.touchCount == 2)
        {
            //Debug.Log("DOS TOQUES");
            if (buttonPressed.IsButtonPressed())
            {
                Debug.Log(coolDownAccumulated + " / " + playerSettings.GetCoolDownTime());
                if (coolDownAccumulated >= playerSettings.GetCoolDownTime())
                {
                    navMeshAgent.destination = transform.position;
                    navMeshAgent.isStopped   = true;
                    Quaternion newRotation = RotatePlayerForShoting(Input.touches[1].position);
                    transform.rotation = newRotation;

                    GameObject bala = Instantiate(balaGO, cañonGO.transform.position, newRotation) as GameObject;
                    bala.GetComponent <BalaMovement>().SetBulletTargetPositon(new Vector3(0, 0, 0));
                    bala.transform.Rotate(new Vector3(90f, 0f, 0f));
                    bala.GetComponent <Rigidbody>().AddForce(transform.forward * playerSettings.GetBulletVelocity());
                    bala.GetComponent <BalaSettings>().SetBalaTeam(playerSettings.GetPlayerTeam());

                    Destroy(bala, playerSettings.GetBulletDestroyingTime());

                    coolDownAccumulated = 0f;
                }
            }
        }
    }