コード例 #1
0
    private void Shoot()
    {
        if (Input.GetButton("Fire1") && waitTillNextFire <= 0)
        {
            int randomNumberForMuzzelFlash = Random.Range(0, 5);

            if (Physics.Raycast(transform.position, transform.forward, out shotRaycastHit, shotMaxDistance,
                                layerMask))
            {
                //Debug.DrawLine(transform.position, shotRaycastHit.point);
                if (shotRaycastHit.transform.gameObject.layer == playerLayer)
                {
                    var shotPlayerId = Int32.Parse(shotRaycastHit.transform.name);
                    if (!clientEntity.OtherPlayerIsDead(shotPlayerId))
                    {
                        clientEntity.SendPlayerShotMessage(shotPlayerId);
                    }
                }
            }

            clientEntity.PlayShot();

            holdFlash = Instantiate(muzzelFlash[randomNumberForMuzzelFlash], muzzelSpawn.transform.position,
                                    muzzelSpawn.transform.rotation * Quaternion.Euler(0, 0, 90));
            holdFlash.transform.parent = muzzelSpawn.transform;

            RecoilMath();
            waitTillNextFire = 1;
        }
        waitTillNextFire -= roundsPerSecond * Time.deltaTime;
    }