Example #1
0
    public void Shoot()
    {
        if (timeForNextShoot <= Time.time)
        {
            timeForNextShoot = Time.time + shootCooldown;

            if (!isServer)
            {
                return;
            }

            ExampleBullet bullet = Instantiate(bulletPrefab, bulletSpawnPosition.position, transform.rotation).GetComponent <ExampleBullet>();
            bullet.ownerNetworkId = NetIdentity.TinyInstanceID.NetworkID;
            bullet.direction      = currentDir;

            bullet.transform.rotation = GetQuaternionForDir(currentDir);

            TinyNetServer.instance.SpawnObject(bullet.gameObject);
        }
    }
Example #2
0
    void ServerShoot(float xPos, float zPos, byte dir)
    {
        if (!isServer)
        {
            rpcRecycleWriter.Reset();
            rpcRecycleWriter.Put(xPos);
            rpcRecycleWriter.Put(zPos);
            rpcRecycleWriter.Put(dir);

            SendRPC(rpcRecycleWriter, "ServerShoot");
            return;
        }

        ExampleBullet bullet = Instantiate(bulletPrefab, bulletSpawnPosition.position, transform.rotation).GetComponent <ExampleBullet>();

        bullet.ownerNetworkId = NetIdentity.NetworkID;
        bullet.direction      = dir;
        switch (dir)
        {
        case 1:
            bullet.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));
            break;

        //Right
        case 2:
            bullet.transform.rotation = Quaternion.Euler(new Vector3(0f, 90f, 0f));
            break;

        //Down
        case 3:
            bullet.transform.rotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));
            break;

        //Left
        case 4:
            bullet.transform.rotation = Quaternion.Euler(new Vector3(0f, 270f, 0f));
            break;
        }

        TinyNetServer.instance.SpawnObject(bullet.gameObject);
    }