3D游戏编程10--多人游戏与网络

游戏机制

场景是沿用巡逻兵的九块区域,在对角线分别创建一个玩家,只要两个玩家相遇就都会被摧毁,同时游戏结束,其中两个玩家有各自的摄像机,各自的动作都会显示。

游戏演示

网络游戏1
网络游戏2

具体实现

代码部分

CameraFlow.cs

实现摄像机跟随玩家,并且随着玩家移动的功能,和单机版的一样

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFlow : MonoBehaviour
{
    public Transform follow;            //跟随的物体
    void Start()
    {

    }

    void FixedUpdate()
    {
        if (follow)
        {
            Vector3 nextpos = follow.forward * -1 * 4 + follow.up * 3 + follow.position;
            this.transform.position = nextpos;
            this.transform.LookAt(new Vector3(follow.position.x, follow.position.y + 2, follow.position.z));
        }
    }
}

NewMove.cs

主要是将以前的移动的代码,单独拿出来,放在玩家上,做成一个预制体
分别是鼠标左键,第一种攻击方式,鼠标右键,第二种攻击方式,空格键,跳跃。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class NewMove : NetworkBehaviour
{
    publ
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值