예제 #1
0
    public void Initialize(HazardSpawner hazardSpawner, int level, Vector3 pos, PlayerID owner = PlayerID.NP, float dir = 1)
    {
        spawner = hazardSpawner;

        if (DataUtility.gameData.isNetworkedGame)
        {
            PunTools.PhotonRpcMine(view, "RPC_Initialize", RpcTarget.AllBuffered, level, pos, owner, dir);
        }
        else
        {
            gameObject.SetActive(true);
            transform.localScale = level * scaleFactor * Vector3.one;
            transform.position   = pos;
            xSpeed      = speed * dir;
            ySpeed      = gravity;
            HazardLevel = level;
            alive       = true;
            hazardOwner = owner;

            thrown     = false;
            throwSpeed = Vector3.zero;

            GetComponent <Renderer>().material.color = DataUtility.GetColorFor(owner);
        }
    }
예제 #2
0
 private void ShootProjectile()
 {
     if (DataUtility.gameData.isNetworkedGame)
     {
         PunTools.PhotonRpcMine(photonView, "RPC_ShootProjectile", RpcTarget.AllBuffered);
     }
     else
     {
         InternalShootProjectile();
     }
 }
예제 #3
0
 public void Damage(float amount)
 {
     if (!invulnerable)
     {
         if (DataUtility.gameData.isNetworkedGame)
         {
             PunTools.PhotonRpcMine(photonView, "RPC_Damage", RpcTarget.AllBuffered, amount);
         }
         else
         {
             health -= amount;
             OnUIShouldUpdate?.Invoke();
             invulnerable = true;
             SetColor(DataUtility.gameData.PlayerInvColor);
             system.emissionRate = 0;
             Invoke("SwitchOfInv", 2.0f);
             SoundManager.Instance.PlaySound(damageClip);
         }
     }
 }
예제 #4
0
    void Update()
    {
        if (!isLocal || !initialized)
        {
            return;
        }

        if (!m_MoveAction.enabled)
        {
            return;
        }

        // Movement
        var move = m_MoveAction.ReadValue <Vector2>();

        if (_charaterController.isGrounded && move.y > 0.4f)
        {
            _moveDirection.y = jumpSpeed;
            animator.SetTrigger("jump");
        }
        _moveDirection.y -= gravity * Time.deltaTime;
        _moveDirection.x  = moveSpeed * move.x;
        _charaterController.Move(_moveDirection * Time.deltaTime);

        if (Mathf.Abs(_moveDirection.x) > 1)
        {
            animator.SetBool("forward", (m_otherPlayer.transform.position.x - transform.position.x) * _moveDirection.x > 0 ? true : false);
            animator.SetBool("backwards", (m_otherPlayer.transform.position.x - transform.position.x) * _moveDirection.x > 0 ? false : true);
        }
        else
        {
            animator.SetBool("forward", false);
            animator.SetBool("backwards", false);
        }

        // Fire
        if (m_FireAction.triggered && throwHazard != null)
        {
            throwHazard.Throw(transform.forward.x > 0 ? false : true, playerID);
        }
        else if (m_FireAction.triggered && _charaterController.isGrounded)
        {
            if (_currentShot == null || !_currentShot.alive)
            {
                animator.SetTrigger("shoot");
                ShootProjectile();
            }
            else if (instantShoot)
            {
                animator.SetTrigger("shoot");
                ShootProjectile();
            }
        }

        if (m_SuperAction.triggered && super >= 100f)
        {
            super = 0f;
            OnUIShouldUpdate?.Invoke();

            if (DataUtility.gameData.isNetworkedGame)
            {
                PunTools.PhotonRpcMine(photonView, "RPC_Super", RpcTarget.MasterClient);
            }
            else
            {
                DoSuperInteral();
            }
        }

        transform.position = new Vector3(transform.position.x, transform.position.y, 0f);

        if (m_otherPlayer != null)
        {
            transform.forward = new Vector3((m_otherPlayer.transform.position.x - transform.position.x) > 0 ? 1 : -1, 0, 0);
        }
    }