Exemplo n.º 1
0
    /// <summary>
    /// Throws the object to a given position by converting the final position to velocity.
    /// </summary>
    /// <param name="_finalPosition">Final position where the object is supposed to be at the end of the trajectory.</param>
    /// <param name="_angle">Throw angle.</param>
    /// <param name="_bonusDamage">Bonus damages added to the attack.</param>
    public virtual void Throw(Vector3 _finalPosition, float _angle, int _bonusDamage)
    {
        if (!isHeld)
        {
            return;
        }

        if (owner.photonView.isMine)
        {
            // Throw the throwable for other players
            TDS_RPCManager.Instance.RPCPhotonView.RPC("CallMethodOnline", PhotonTargets.Others, TDS_RPCManager.GetInfo(photonView, GetType(), "Throw"), new object[] { transform.position.x, transform.position.y, transform.position.z, _finalPosition.x, _finalPosition.y, _finalPosition.z, _angle, _bonusDamage });
        }

        if (PhotonNetwork.isMasterClient)
        {
            ActivateHitbox(_bonusDamage);
        }

        transform.SetParent(null, true);

        rigidbody.isKinematic = false;
        rigidbody.velocity    = TDS_ThrowUtility.GetProjectileVelocityAsVector3(transform.position, _finalPosition, _angle);

        collider.enabled = true;
        isHeld           = false;

        owner.RemoveThrowable();
    }
    /// <summary>
    /// Modify the Throwable Position as in <see cref="TDS_Throwable.Throw(Vector3, float, int)"/>
    /// But don't Activate the hitbox
    /// </summary>
    /// <param name="_finalPosition"></param>
    /// <param name="_angle"></param>
    /// <param name="_bonusDamage"></param>
    public override void Throw(Vector3 _finalPosition, float _angle, int _bonusDamage)
    {
        if (!isHeld)
        {
            return;
        }

        if (owner.photonView.isMine)
        {
            // Throw the throwable for other players
            TDS_RPCManager.Instance.RPCPhotonView.RPC("CallMethodOnline", PhotonTargets.Others, TDS_RPCManager.GetInfo(photonView, GetType(), "Throw"), new object[] { transform.position.x, transform.position.y, transform.position.z, _finalPosition.x, _finalPosition.y, _finalPosition.z, _angle, _bonusDamage });
        }

        transform.SetParent(null, true);

        rigidbody.isKinematic = false;
        rigidbody.velocity    = TDS_ThrowUtility.GetProjectileVelocityAsVector3(transform.position, _finalPosition, _angle);

        collider.enabled = true;

        owner.RemoveThrowable();

        gameObject.layer = LayerMask.NameToLayer("Object");

        if (hitBox.IsActive)
        {
            hitBox.Desactivate();
        }
        Tags _hitableTags = owner.HitBox.HittableTags;

        if (owner is TDS_Enemy)
        {
            _hitableTags.AddTag("Enemy");
        }
        isHeld = false;
        if (explosionCoroutine == null)
        {
            explosionCoroutine = StartCoroutine(SetupExplosion(_hitableTags));
        }
    }