예제 #1
0
    private void DesktopUpdate()
    {
        if (PhotonNetwork.IsConnected && !photonView.IsMine)
        {
            return;
        }

        //CoolDown management
        if (coolDownAccumulated < playerSettings.GetCoolDownTime())
        {
            coolDownAccumulated += Time.deltaTime;
        }

        if (Input.GetMouseButtonDown(0))
        {
            Vector3 raycastHit = getRayCastPoint(Input.mousePosition);
            if (raycastHit != Vector3.zero)
            {
                navMeshAgent.destination = raycastHit;
                navMeshAgent.isStopped   = false;
            }

            dashed             = false;
            touchStartPosition = null;
        }
        else if (Input.GetMouseButtonDown(1))
        {
            Debug.Log(coolDownAccumulated + " / " + playerSettings.GetCoolDownTime());
            if (coolDownAccumulated >= playerSettings.GetCoolDownTime())
            {
                navMeshAgent.destination = transform.position;
                navMeshAgent.isStopped   = true;
                Quaternion newRotation = RotatePlayerForShoting(Input.mousePosition);
                transform.rotation = newRotation;

                GameObject bala = null;
                if (!PhotonNetwork.IsConnected)
                {
                    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());
                }
                else
                {
                    //Hay que pasarle parámetros a la bala de networking
                    //[0] -> BalaTeam
                    //bala = PhotonNetwork.Instantiate(balaGO.name, cañonGO.transform.position, newRotation, 0, new object[] { playerSettings.GetPlayerTeam() }) as GameObject;

                    //Vamos a intentar Instanciar con RPC
                    Debug.Log("Antes del disparo");
                    photonView.RPC("InstantiateBullet", RpcTarget.All, new object[] { newRotation, getRayCastPoint(Input.mousePosition) });
                }

                //Esto se hace para los dos porque el transform de la bala ya se está observando.

                //Destroy(bala, playerSettings.GetBulletDestroyingTime());

                coolDownAccumulated = 0f;
            }
        }
    }