【Unity插件Mirror】射击游戏样例学习(二)
![](/assets/blank.gif)
using UnityEngine;
namespace QuickStart
{public class SceneReference : MonoBehaviour{public SceneScript sceneScript;}
}
![](/assets/blank.gif)
![](/assets/blank.gif)
using UnityEngine.SceneManagement;
public void ButtonChangeScene()
{if (isServer){Scene scene = SceneManager.GetActiveScene();if (scene.name == "MainScene") { NetworkManager.singleton.ServerChangeScene("MyOtherScene"); } else { NetworkManager.singleton.ServerChangeScene("MainScene"); }}else { Debug.Log("You are not Host."); }
}
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
using UnityEngine;
using UnityEngine.SceneManagement;
namespace QuickStart
{public class Menu : MonoBehaviour{public void LoadScene(){SceneManager.LoadScene("GamesList");}}
}
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
using UnityEngine;
using UnityEngine.SceneManagement;
namespace QuickStart
{public class GamesList : MonoBehaviour{public void LoadScene(){SceneManager.LoadScene("Menu");}}
}
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
using UnityEngine;
namespace QuickStart
{public class Weapon : MonoBehaviour{public float weaponSpeed = 15.0f;public float weaponLife = 3.0f;public float weaponCooldown = 1.0f;public int weaponAmmo = 15;public GameObject weaponBullet;public Transform weaponFirePosition;}
}
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
public Text canvasAmmoText;public void UIAmmo(int _value)
{canvasAmmoText.text = "Ammo: " + _value;
}
![](/assets/blank.gif)
private Weapon activeWeapon;
private float weaponCooldownTime;
void OnWeaponChanged(int _Old, int _New)
{// disable old weapon// in range and not nullif (0 < _Old && _Old < weaponArray.Length && weaponArray[_Old] != null){weaponArray[_Old].SetActive(false);}// enable new weapon// in range and not nullif (0 < _New && _New < weaponArray.Length && weaponArray[_New] != null){weaponArray[_New].SetActive(true);activeWeapon = weaponArray[activeWeaponSynced].GetComponent<Weapon>();if( isLocalPlayer ) { sceneScript.UIAmmo(activeWeapon.weaponAmmo); }}
}
if (selectedWeaponLocal < weaponArray.Length && weaponArray[selectedWeaponLocal] != null)
{ activeWeapon = weaponArray[selectedWeaponLocal].GetComponent<Weapon>(); sceneScript.UIAmmo(activeWeapon.weaponAmmo); }
if (Input.GetButtonDown("Fire1") ) //Fire1 is mouse 1st click
{if (activeWeapon && Time.time > weaponCooldownTime && activeWeapon.weaponAmmo > 0){weaponCooldownTime = Time.time + activeWeapon.weaponCooldown;activeWeapon.weaponAmmo -= 1;sceneScript.UIAmmo(activeWeapon.weaponAmmo);CmdShootRay();}
}
[Command]
void CmdShootRay()
{RpcFireWeapon();
}
[ClientRpc]
void RpcFireWeapon()
{//bulletAudio.Play(); muzzleflash etcvar bullet = (GameObject)Instantiate(activeWeapon.weaponBullet, activeWeapon.weaponFirePosition.position, activeWeapon.weaponFirePosition.rotation);bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * activeWeapon.weaponSpeed;if (bullet) { Destroy(bullet, activeWeapon.weaponLife); }
}
![](/assets/blank.gif)
【Unity插件Mirror】射击游戏样例学习(二)相关推荐
- unity第三人称射击游戏_在游戏上第3部分完美的信息游戏
unity第三人称射击游戏 Previous article 上一篇文章 The economics literature distinguishes the quality of a game's ...
- Unity 3D为策略游戏创建地图学习教程
MP4 |视频:h264,1280×720 |音频:AAC,44.1 KHz,2 Ch 语言:英语+中英文字幕(根据原英文字幕机译更准确) |时长:30节课(7h 42m) |大小:5 GB 含项目文 ...
- 模式识别 - 处理多演示样例学习(MIL)特征(matlab)
处理多演示样例学习(MIL)特征(matlab) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/27206325 多演示样例学习( ...
- unity太空飞机射击游戏
unity太空飞机射击游戏 有分数和生命值,飞机可以对其他飞行物进行射击,分数提高后飞机可以升级,具体情况如下图: 点我下载资源
- unity第一人称射击游戏,枪击游戏,功能完整可以当大作业或者毕设
unity第一人称射击游戏,枪击游戏(含源码和exe导出文件,下载链接在文末) unity第一人称枪击游戏,分为海岛地图和沙漠地图,可以开镜射击,敌人可以移动,菜单页面有开始游戏,游戏说明,退出三个按 ...
- Unity 第三人称射击游戏视角控制与武器瞄准
===================更新一下源工程链接: 链接:https://pan.baidu.com/s/15bxH-MPregp2ZIN92fK7XA 提取码:e7bp ========== ...
- Dubbo 新增本地 IDE 插件,快速创建样例工程
Cloud Toolkit 是一个 IDE 插件,帮助开发者更高效地开发.测试.诊断并部署应用. Dubbo 采用全 Spring 配置方式,透明化接入应用,对应用没有任何 API 侵入,只需用 Sp ...
- Unity之简单射击游戏案例
PS:该案例来自学习的课本和我自己的理解.首次文章创作,还请多多支持呀各位美女.帅哥们!!! *废话不多说先上游戏实机操作视频* 射击游戏实机操作_Trim 游戏内容大致如下: (1)完全使用键盘控制 ...
- 【Unity实战】制作类元气骑士、挺进地牢——俯视角射击游戏多种射击效果(二)(附源码)
文章目录 前言 一.火箭筒 1. 编写火箭筒脚本 2. 创建火箭弹和新爆炸特效的预制体 3. 编写火箭弹脚本 4. 设置好火箭弹和火箭筒的脚本和参数 5. 运行效果 二.激光枪 1. 编写激光枪脚本 ...
最新文章
- BugkuCTF web3
- linux 查端口 三种,Linux查看端口常用的三种用例
- Pinnacle Studio Ultimate中文版
- 计算机专业350分能进复试吗,初试估分350分,这在考研中算一个什么水平?
- 添加图标_win10系统轻松添加显示桌面图标的操作方法
- Java多对多关系示例
- Maven学习总结(43)——利用javadoc插件生成项目的API文档
- 4.Shell 编程从入门到精通 --- 正则表达式
- 在家或者公司如何登录服务器
- UVa11137 - Ingenuous Cubrency
- rust闪退修复工具_Rust的错误处理
- 拼多多砍价背后的逻辑
- 震为雷:始于足下;艮为山:红灯刹车
- SSL用pem和key文件生成jks文件
- 【我是初学者】关于获取配置文件.properties的常见三种方式--只是常见的方式,欢迎牛神来加瓦
- 想买折叠手机的你,了解OLED显示很有必要
- 让微积分穿梭于工作与学习之间(29):夹逼公式的几种变体
- php handle 用用法,PHP_关于php fread()使用技巧,说明 string fread ( int handle, int le - phpStudy...
- 怎样提高神马推广转换效率?
- 运维不是修电脑!月薪30K的高级运维告诉你,学会这些就能逆袭