コード例 #1
0
ファイル: PlayerShoot.cs プロジェクト: Yaruno292/networkFps
 void DealDmgPlayer()
 {
     if (!isServer)
     {
         return;
     }
     playerTarget.TakeDmg(damage);
 }
コード例 #2
0
ファイル: PlayerShoot.cs プロジェクト: Yaruno292/networkFps
    void Shoot()
    {
        StartCoroutine(TBB(currentWeaponTbb));
        particles[currentWeapon].Play();
        audioSource.clip = ShotSounds[currentWeapon];
        audioSource.Play();


        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            target       = hit.transform.GetComponent <Target>();
            playerTarget = hit.transform.GetComponent <PlayerTarget>();

            if (target != null)
            {
                target.TakeDmg(damage);
                DealDmgObj();
                Debug.Log("takes dmg");
            }

            if (playerTarget != null)
            {
                playerTarget.TakeDmg(damage);
                DealDmgPlayer();
                Debug.Log("player hit");
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
                KnockBack();
                Debug.Log("adds knockback");
            }
        }

        Debug.Log("shoots");
        GameObject impactObj = Instantiate(impactParticle, hit.point, Quaternion.LookRotation(hit.normal));

        Destroy(impactObj, 2f);
        NetworkServer.Spawn(impactObj);
        if (t < 0)
        {
            NetworkServer.Destroy(impactObj);
            t = 2f;
        }
        else
        {
            t -= Time.deltaTime;
        }

        weapons[currentWeapon].GetComponent <Animation>().Play();
    }
コード例 #3
0
ファイル: NadeExplode.cs プロジェクト: Yaruno292/networkFps
    private void CmdExplode()
    {
        GameObject expl = Instantiate(explosion, transform.position, transform.rotation);

        NetworkServer.Spawn(expl);
        Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, raduis);

        foreach (Collider nearObj in collidersToDestroy)
        {
            Target       target       = nearObj.GetComponent <Target>();
            PlayerTarget playerTarget = nearObj.GetComponent <PlayerTarget>();
            if (target != null)
            {
                target.TakeDmg(damage);
            }
            if (playerTarget != null)
            {
                playerTarget.TakeDmg(damage);
            }
        }

        foreach (Collider nearTerrain in collidersToDestroy)
        {
            Terrain terrain = nearTerrain.GetComponent <Terrain>();
            if (terrain != null)
            {
                terrainD.DestroyTerrain();
            }
            else
            {
                NetworkServer.Destroy(gameObject);
                Destroy(gameObject);
            }
        }


        Collider[] collidersToMove = Physics.OverlapSphere(transform.position, raduis);

        foreach (Collider nearObj in collidersToMove)
        {
            Rigidbody rb = nearObj.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, raduis);
            }
        }
    }