public void DoPullPin(AudioClip clip, int gID)
    {
        GetComponent <AudioSource>().PlayOneShot(clip);
        displayMesh.enabled = false;
        currentExplosive    = (Rigidbody)Instantiate(grenadePrefab, displayMesh.transform.position, displayMesh.transform.rotation);
        currentExplosive.transform.parent = transform;
        currentExplosive.isKinematic      = true;

        if (currentExplosive.GetComponent <Collider>() != null)
        {
            currentExplosive.GetComponent <Collider>().enabled = false;
        }

        GrenadeScript    greS  = currentExplosive.GetComponent <GrenadeScript>();
        PlasticExplosive pExpl = currentExplosive.GetComponent <PlasticExplosive>();

        if (greS != null)
        {
            greS.PulledPin();
            greS.onlyVisual = true;
            greS.myID       = gID;
        }
        else if (pExpl != null)
        {
            whp.detonationList.Add(pExpl);
            pExpl.onlyVisual = true;
            pExpl.myID       = gID;
        }
    }
Example #2
0
    public void PullPin()
    {
        displayMesh.enabled = false;
        grenadeInstance     = (Rigidbody)Instantiate(grenadePrefab, displayMesh.transform.position, displayMesh.transform.rotation);
        grenadeInstance.transform.parent   = transform;
        grenadeInstance.transform.position = displayMesh.transform.position;
        grenadeInstance.isKinematic        = true;

        if (grenadeInstance.GetComponent <Collider>() != null)
        {
            grenadeInstance.GetComponent <Collider>().enabled = false;
        }

        int              newSyncID = Random.Range(0, 9999999);
        GrenadeScript    gScript   = grenadeInstance.GetComponent <GrenadeScript>();
        PlasticExplosive pExpl     = grenadeInstance.GetComponent <PlasticExplosive>();

        if (Topan.Network.isConnected && wm.rootNetView != null)
        {
            wm.rootNetView.RPC(Topan.RPCMode.Others, "PullPinGrenade", newSyncID);
        }

        if (isDetonatable)
        {
            if (pExpl != null)
            {
                pExpl.enabled = false;
                pExpl.myID    = newSyncID;
            }
        }
        else
        {
            if (gScript != null)
            {
                gScript.PulledPin();
                gScript.myID       = newSyncID;
                gScript.databaseID = grenadeID;
            }
        }

        GetComponent <AudioSource>().PlayOneShot(pullPinSound);

        pullPinTime = Time.time;
        pulledPin   = true;
    }
Example #3
0
    public void Throw(float strength)
    {
        if (grenadeInstance != null)
        {
            gam.ChangeGrenadeAmount(grenadeID, -1);
            GetComponent <AudioSource>().PlayOneShot(throwSound);

            grenadeInstance.transform.parent = null;
            grenadeInstance.isKinematic      = false;

            if (grenadeInstance.GetComponent <Collider>() != null)
            {
                grenadeInstance.GetComponent <Collider>().enabled = true;
            }

            Vector3 dir  = throwPos.transform.forward + (Vector3)(Random.insideUnitCircle * 0.025f);
            Vector3 velo = (pm.controller.velocity * 0.5f) + ((dir + (Vector3.up * 0.1f)) * strength);
            grenadeInstance.velocity        = velo;
            grenadeInstance.angularVelocity = new Vector3(1f, 0.69f, 0.86f) * 4.5f;

            if (Topan.Network.isConnected && wm.rootNetView != null)
            {
                wm.rootNetView.RPC(Topan.RPCMode.Others, "ThrowGrenade", velo, grenadeInstance.transform.position);
            }

            PlasticExplosive pExpl = grenadeInstance.GetComponent <PlasticExplosive>();
            if (isDetonatable && pExpl != null)
            {
                gm.detonationList.Add(pExpl);
                pExpl.enabled = true;
            }

            canThrow       = false;
            pulledPin      = false;
            targetStrength = 0f;

            GetGrenadeValues();

            grenadeInstance = null;
        }
    }