test
testing
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//This script is used to synchronize character animation over Network
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class AnimationSync : Photon.MonoBehaviour {
|
||||
|
||||
//GameObject which contain all third person weapons
|
||||
public Transform thirdPersonWeapons;
|
||||
//Assign following Armature bones for separated animation blending
|
||||
public Transform shoulderR;
|
||||
public Transform shoulderL;
|
||||
//Use this object to receive animations that were sent from CharacterAnimation.js
|
||||
public GameObject animationSyncHelper;
|
||||
public GameObject animationForHands;
|
||||
//This gameObject.name tell which third person weapon is active now
|
||||
public GameObject activeWeapon;
|
||||
|
||||
public HeadLookController headLookController;
|
||||
|
||||
//We store animation names that were give MixedTransform
|
||||
//So we add Mixed Transform only once for each needed animation
|
||||
List<string> mixedAnimations = new List<string>();
|
||||
|
||||
|
||||
string MovementAnimation;
|
||||
//Copy received blended animation
|
||||
string currentBlendedAnimation;
|
||||
string currentWeaponName;
|
||||
|
||||
private string currentAnimation = "";
|
||||
private string blendedAnimation = "";
|
||||
private string prevWeap = "";
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
if (photonView.isMine){
|
||||
Destroy(headLookController);
|
||||
}
|
||||
}
|
||||
|
||||
//Synchronize player animation
|
||||
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
|
||||
if (stream.isWriting){
|
||||
//We own this player: send the others our data
|
||||
stream.SendNext(animationSyncHelper.name);
|
||||
stream.SendNext(animationForHands.name);
|
||||
stream.SendNext(activeWeapon.name);
|
||||
}else{
|
||||
//Network player, receive data
|
||||
currentAnimation = (string)stream.ReceiveNext();
|
||||
blendedAnimation = (string)stream.ReceiveNext();
|
||||
currentWeaponName = (string)stream.ReceiveNext();
|
||||
}
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (!photonView.isMine){
|
||||
//Base movement animations
|
||||
if(MovementAnimation != currentAnimation){
|
||||
//animation.Stop();
|
||||
MovementAnimation = currentAnimation;
|
||||
}
|
||||
if(animation[MovementAnimation] != null){
|
||||
animation[MovementAnimation].layer = 1;
|
||||
animation[MovementAnimation].wrapMode = WrapMode.Loop;
|
||||
animation.CrossFade(MovementAnimation);
|
||||
}
|
||||
|
||||
//Blended weapon animations (Pistol Idle, Knife Idle etc.)
|
||||
//If blended animation == "Null" mean that we dont need mixing animation at the moment, so disable them
|
||||
if(currentBlendedAnimation != blendedAnimation){
|
||||
currentBlendedAnimation = blendedAnimation;
|
||||
if(!mixedAnimations.Contains(currentBlendedAnimation) && currentBlendedAnimation != "Null" && animation[currentBlendedAnimation] != null){
|
||||
animation[currentBlendedAnimation].layer = 4;
|
||||
animation[currentBlendedAnimation].wrapMode = WrapMode.Loop;
|
||||
animation[currentBlendedAnimation].AddMixingTransform(shoulderR);
|
||||
animation[currentBlendedAnimation].AddMixingTransform(shoulderL);
|
||||
mixedAnimations.Add (currentBlendedAnimation);
|
||||
}
|
||||
}
|
||||
if(currentBlendedAnimation != "Null" && animation[currentBlendedAnimation] != null){
|
||||
animation.Play(currentBlendedAnimation);
|
||||
}
|
||||
|
||||
//Change third person weapon
|
||||
if(prevWeap != currentWeaponName){
|
||||
for(int i = 0; i < thirdPersonWeapons.childCount; i++){
|
||||
if(thirdPersonWeapons.GetChild(i).name != currentWeaponName){
|
||||
thirdPersonWeapons.GetChild(i).gameObject.SetActiveRecursively(false);
|
||||
}else{
|
||||
thirdPersonWeapons.GetChild(i).gameObject.SetActiveRecursively(true);
|
||||
}
|
||||
}
|
||||
prevWeap = currentWeaponName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 903e54450bb88084b89bf20e6cc5f1bd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,209 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//Implementation of Photon Networking system
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ConnectMenu : Photon.MonoBehaviour {
|
||||
|
||||
public GUISkin guiSKin;
|
||||
//Use this for loading splash screen
|
||||
public Texture2D blackScreen;
|
||||
string newRoomName;
|
||||
|
||||
[HideInInspector]
|
||||
public string playerName;
|
||||
public GUIStyle labelStyle;
|
||||
|
||||
[HideInInspector]
|
||||
public bool connectingToRoom = false;
|
||||
RoomMultiplayerMenu pmn;
|
||||
MultiplayerChat mc;
|
||||
RoomInfo[] allRooms;
|
||||
Vector2 scroll;
|
||||
//Fade black screen
|
||||
[HideInInspector]
|
||||
public float fadeValue = new float();
|
||||
[HideInInspector]
|
||||
public int fadeDir;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
transform.GetChild(0).gameObject.camera.farClipPlane = 1;
|
||||
//Connect to Photon Cloud
|
||||
/*if(!PhotonNetwork.connected)
|
||||
PhotonNetwork.ConnectUsingSettings("v1.0");*/
|
||||
|
||||
allRooms = PhotonNetwork.GetRoomList();
|
||||
newRoomName = "Room Name " + Random.Range(111, 999);
|
||||
playerName = "Player " + Random.Range(111, 999);
|
||||
pmn = GetComponent<RoomMultiplayerMenu>();
|
||||
mc = GetComponent<MultiplayerChat>();
|
||||
pmn.enabled = false;
|
||||
mc.enabled = false;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
//Try to reconnect every 3 seconds
|
||||
float updateRate = 3;
|
||||
float nextUpdateTime = 0;
|
||||
//Do not try connect every frame, but using small intervals (To avoid lag while failed to connect)
|
||||
if(!PhotonNetwork.connected){
|
||||
if (Time.time - updateRate > nextUpdateTime){
|
||||
nextUpdateTime = Time.time - Time.deltaTime;
|
||||
}
|
||||
// Keep firing until we used up the fire time
|
||||
while(nextUpdateTime < Time.time){
|
||||
PhotonNetwork.ConnectUsingSettings("v2.4");
|
||||
nextUpdateTime += updateRate;
|
||||
}
|
||||
}
|
||||
|
||||
//FInd all existing rooms
|
||||
if(PhotonNetwork.connected && allRooms.Length != PhotonNetwork.GetRoomList().Length){
|
||||
allRooms = PhotonNetwork.GetRoomList();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void OnGUI () {
|
||||
GUI.skin = guiSKin;
|
||||
|
||||
fadeScreen();
|
||||
|
||||
GUI.color = Color.white;
|
||||
GUI.depth = -2;
|
||||
//If we havnt connected to Photon Cloud do not allow player to join/create room
|
||||
if(!PhotonNetwork.connected){
|
||||
GUI.Box (new Rect(Screen.width/2 - 75, Screen.height/2 - 15, 150, 30), "Connecting...");
|
||||
GUI.enabled = false;
|
||||
}else{
|
||||
GUI.enabled = true;
|
||||
}
|
||||
if(PhotonNetwork.room != null && PhotonNetwork.connected)
|
||||
return;
|
||||
GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 300), connectMenu, "FPS Kit 2.0 | Multiplayer Test v2.4");
|
||||
}
|
||||
|
||||
void connectMenu(int id){
|
||||
GUILayout.Space (10);
|
||||
/*GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
if(GUILayout.Button("Refresh")){
|
||||
allRooms = PhotonNetwork.GetRoomList();
|
||||
}
|
||||
GUILayout.EndHorizontal();*/
|
||||
|
||||
//DIsplay all available rooms
|
||||
//Join selected room
|
||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(480), GUILayout.Height(200));{
|
||||
foreach(RoomInfo room in allRooms){
|
||||
if(allRooms.Length > 0){
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(room.name);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
//Player count
|
||||
GUILayout.Label(room.playerCount + "/" + room.maxPlayers);
|
||||
GUILayout.Space (100);
|
||||
if(GUILayout.Button("Join Room")){
|
||||
//Join a room
|
||||
PhotonNetwork.JoinRoom(room.name);
|
||||
PhotonNetwork.playerName = playerName;
|
||||
connectingToRoom = true;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
if(allRooms.Length == 0){
|
||||
GUILayout.Label("No rooms created...");
|
||||
}
|
||||
GUILayout.EndScrollView();}
|
||||
|
||||
//Choose player name
|
||||
GUILayout.BeginHorizontal();
|
||||
playerName = GUILayout.TextField (playerName, 15, GUILayout.Width(345), GUILayout.Height(25));
|
||||
GUILayout.Label("< Player Name", labelStyle);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
//Create new room
|
||||
GUILayout.BeginHorizontal();
|
||||
newRoomName = GUILayout.TextField (newRoomName, 35, GUILayout.Width(345), GUILayout.Height(25));
|
||||
GUILayout.FlexibleSpace();
|
||||
if(GUILayout.Button("Create Room")){
|
||||
//Create this room.
|
||||
PhotonNetwork.CreateRoom(newRoomName, true, true, 20);
|
||||
PhotonNetwork.playerName = playerName;
|
||||
// Fails if it already exists and calls: OnPhotonCreateGameFailed
|
||||
allRooms = PhotonNetwork.GetRoomList();
|
||||
connectingToRoom = true;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnJoinedRoom(){
|
||||
print ("Joined room: " + newRoomName);
|
||||
connectingToRoom = false;
|
||||
transform.GetChild(0).gameObject.camera.farClipPlane = 600;
|
||||
pmn.enabled = true;
|
||||
mc.enabled = true;
|
||||
pmn.isPaused = true;
|
||||
connectingToRoom = false;
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
void fadeScreen(){
|
||||
if(connectingToRoom){
|
||||
fadeDir = 1;
|
||||
fadeValue += fadeDir * 15 * Time.deltaTime;
|
||||
fadeValue = Mathf.Clamp01(fadeValue);
|
||||
|
||||
//GUI.color = Color.white;
|
||||
//GUI.Label(new Rect(Screen.width/2 - 75, Screen.height/2 - 15, 150, 30), "Loading...");
|
||||
GUI.color = new Color(1,1,1,fadeValue);
|
||||
GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height), blackScreen);
|
||||
}
|
||||
}
|
||||
|
||||
void OnJoinedLobby(){
|
||||
print ("Joined master server");
|
||||
}
|
||||
|
||||
void OnLeftRoom(){
|
||||
transform.GetChild(0).gameObject.camera.farClipPlane = 1;
|
||||
allRooms = PhotonNetwork.GetRoomList();
|
||||
connectingToRoom = false;
|
||||
}
|
||||
|
||||
void OnPhotonJoinRoomFailed(){
|
||||
print ("Failed on connecting to room");
|
||||
connectingToRoom = false;
|
||||
}
|
||||
|
||||
void OnPhotonCreateRoomFailed(){
|
||||
print ("Failed on creating room");
|
||||
connectingToRoom = false;
|
||||
}
|
||||
|
||||
void OnPhotonPlayerConnected(){
|
||||
print ("Player connected");
|
||||
}
|
||||
|
||||
//We just connected to Photon Cloud
|
||||
void OnConnectedToPhoton(){
|
||||
if(PhotonNetwork.room != null){
|
||||
PhotonNetwork.LeaveRoom();
|
||||
}
|
||||
connectingToRoom = false;
|
||||
|
||||
}
|
||||
|
||||
void OnDisconnectedFromPhoton(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5fe6ef7b85fe1c47a5d5582f3eaa94d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,16 @@
|
||||
//This script will be attached automatically to every hit box
|
||||
//It will receive damage and transmit it to PlayerDamage.cs
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class HitBox : MonoBehaviour {
|
||||
|
||||
public float maxDamage;
|
||||
public PlayerDamage playerDamage;
|
||||
|
||||
void ApplyDamage(float damage){
|
||||
//So we receive bullet damage and also add other damage value we have configured in PlayerDamage.cs
|
||||
playerDamage.totalDamage(damage + maxDamage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a1e977d9db5dfc4f9609dcf5676eb9b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,134 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MultiplayerChat : Photon.MonoBehaviour{
|
||||
|
||||
public static MultiplayerChat SP;
|
||||
|
||||
public struct ChatData {
|
||||
public string name { get; set; }
|
||||
public string text { get; set; }
|
||||
|
||||
public ChatData(string string1, string string2){
|
||||
name = string1;
|
||||
text = string2;
|
||||
}
|
||||
|
||||
}
|
||||
public List<ChatData> messages = new List<ChatData>();
|
||||
|
||||
private int chatHeight = (int)300;
|
||||
private Vector2 scrollPos = Vector2.zero;
|
||||
[HideInInspector]
|
||||
public string chatInput = "";
|
||||
[HideInInspector]
|
||||
public bool isChatting;
|
||||
public GUIStyle chatStyle;
|
||||
|
||||
void Awake(){
|
||||
SP = this;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if(Input.GetKey(KeyCode.T) && !isChatting){
|
||||
this.StopAllCoroutines();
|
||||
StartCoroutine(ereaseChat());
|
||||
}
|
||||
|
||||
if(messages.Count > 12){
|
||||
messages.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ereaseChat(){
|
||||
yield return new WaitForSeconds(0.07f);
|
||||
isChatting = true;
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
GUILayout.BeginArea(new Rect(5, Screen.height - chatHeight-50, Screen.width, chatHeight+10));
|
||||
|
||||
//Show scroll list of chat messages
|
||||
scrollPos = GUILayout.BeginScrollView(scrollPos);
|
||||
GUI.color = Color.white;
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
for (int i = 0; i < messages.Count; i++){
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.color = Color.green;
|
||||
GUILayout.Label(messages[i].name, chatStyle);
|
||||
GUILayout.Space(5);
|
||||
GUI.color = Color.white;
|
||||
GUILayout.Label(messages[i].text, chatStyle);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
|
||||
GUILayout.BeginArea(new Rect(5, Screen.height - 35, Screen.width, 30));
|
||||
if (Event.current.type == EventType.keyDown && Event.current.character == '\n'){
|
||||
isChatting = false;
|
||||
SendChat(PhotonTargets.All);
|
||||
}
|
||||
|
||||
//Chat input
|
||||
if(isChatting){
|
||||
GUI.FocusControl("ChatField");
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.SetNextControlName("ChatField");
|
||||
GUI.color = Color.red;
|
||||
GUILayout.Label("Say: ", chatStyle);
|
||||
GUILayout.Space(5);
|
||||
GUI.color = Color.white;
|
||||
chatInput = GUILayout.TextField(chatInput, chatStyle, GUILayout.MinWidth(200));
|
||||
GUILayout.EndHorizontal();
|
||||
}else{
|
||||
GUI.FocusControl("");
|
||||
}
|
||||
GUILayout.EndArea();
|
||||
|
||||
}
|
||||
|
||||
public static void AddMessage(string name, string text){
|
||||
SP.messages.Add(new ChatData(name, text));
|
||||
//Message count limit
|
||||
if (SP.messages.Count > 13)
|
||||
SP.messages.RemoveAt(0);
|
||||
}
|
||||
|
||||
|
||||
[RPC]
|
||||
void SendChatMessage(string text, PhotonMessageInfo info){
|
||||
AddMessage(" " + info.sender + ": ", text);
|
||||
}
|
||||
|
||||
void SendChat(PhotonTargets target){
|
||||
if (chatInput != ""){
|
||||
string tempChat =" " + chatInput;
|
||||
photonView.RPC("SendChatMessage", target, tempChat);
|
||||
chatInput = "";
|
||||
}
|
||||
}
|
||||
|
||||
void SendChat(PhotonPlayer target){
|
||||
if (chatInput != ""){
|
||||
chatInput = "[PM] " + chatInput;
|
||||
photonView.RPC("SendChatMessage", target, chatInput);
|
||||
chatInput = "";
|
||||
}
|
||||
}
|
||||
|
||||
void OnLeftRoom(){
|
||||
messages.Clear();
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
void OnJoinedRoom(){
|
||||
this.enabled = true;
|
||||
}
|
||||
void OnCreatedRoom(){
|
||||
this.enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2937d40eb226dcf4b83760e950ac9663
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,145 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//This script is used to controll player health
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class PlayerDamage : Photon.MonoBehaviour {
|
||||
|
||||
public GUISkin guiSKin;
|
||||
//Player health
|
||||
public float hp = 100;
|
||||
public GameObject ragdoll;
|
||||
public Texture2D bloodyScreen;
|
||||
public Texture2D hitMarkTexture;
|
||||
//Hitboxes and damage properties for each
|
||||
[System.Serializable]
|
||||
public class HitBoxes {
|
||||
public Collider box /*{ get; set; } */;
|
||||
public float damage /*{ get; set; }*/;
|
||||
|
||||
public HitBoxes(Collider box1, float damage1){
|
||||
box = box1;
|
||||
damage = damage1;
|
||||
}
|
||||
|
||||
}
|
||||
public List<HitBoxes> hitBoxes = new List<HitBoxes>();
|
||||
|
||||
[HideInInspector]
|
||||
public float currentHp;
|
||||
Quaternion camRot;
|
||||
Quaternion camDefaultRotation;
|
||||
//Fade hit mark
|
||||
float fadeValue;
|
||||
//Fade bloody screen
|
||||
float fadeValueB;
|
||||
|
||||
void Awake(){
|
||||
camDefaultRotation = Camera.main.transform.localRotation;
|
||||
currentHp = hp;
|
||||
if(!photonView.isMine){
|
||||
for(int i = 0; i < hitBoxes.Count;i++){
|
||||
hitBoxes[i].box.gameObject.AddComponent<HitBox>();
|
||||
hitBoxes[i].box.gameObject.GetComponent<HitBox>().maxDamage = hitBoxes[i].damage;
|
||||
hitBoxes[i].box.gameObject.GetComponent<HitBox>().playerDamage = this;
|
||||
hitBoxes[i].box.isTrigger = true;
|
||||
}
|
||||
}else{
|
||||
for(int a = 0; a < hitBoxes.Count;a++){
|
||||
//We dont need our hit boxes, destroy them
|
||||
Destroy (hitBoxes[a].box.collider);
|
||||
}
|
||||
hitBoxes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void totalDamage(float damage){
|
||||
fadeValue = 2;
|
||||
photonView.RPC("doDamage", PhotonTargets.All, damage);
|
||||
if(weKilled){
|
||||
//Send death notification message to script WhoKilledWho.cs
|
||||
GameObject.FindWithTag("Network").SendMessage("AddKillNotification", gameObject.name, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
bool weKilled;
|
||||
|
||||
[RPC]
|
||||
void doDamage(float damage){
|
||||
if(weKilled)
|
||||
return;
|
||||
if(currentHp > 0 && photonView.isMine){
|
||||
this.StopAllCoroutines();
|
||||
StartCoroutine(doCameraShake());
|
||||
}
|
||||
|
||||
fadeValueB = 2;
|
||||
|
||||
currentHp -= damage;
|
||||
|
||||
//We got killed
|
||||
if(currentHp < 0){
|
||||
GameObject temp;
|
||||
temp = Instantiate(ragdoll, transform.position, transform.rotation) as GameObject;
|
||||
|
||||
gameObject.SetActiveRecursively(false);
|
||||
gameObject.active = true;
|
||||
|
||||
if(photonView.isMine){
|
||||
print ("We got killed");
|
||||
|
||||
foreach(PhotonView p in transform.GetComponentsInChildren<PhotonView>()){
|
||||
PhotonNetwork.RemoveRPCs(p);
|
||||
}
|
||||
temp.SendMessage("RespawnAfter");
|
||||
|
||||
StartCoroutine(photonDestroy());
|
||||
}else{
|
||||
temp.SendMessage("clearCamera");
|
||||
}
|
||||
currentHp = 0;
|
||||
weKilled = true;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator photonDestroy(){
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
PhotonNetwork.Destroy(gameObject);
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
//Display HP for our player only
|
||||
if(photonView.isMine){
|
||||
GUI.skin = guiSKin;
|
||||
GUI.color = new Color(1,1,1,0.9f);
|
||||
GUI.depth = 10;
|
||||
GUI.color = new Color(1,1,1,fadeValueB);
|
||||
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), bloodyScreen, ScaleMode.StretchToFill );
|
||||
GUI.color = new Color(1,1,1,0.9f);
|
||||
//Display player hp
|
||||
GUI.Box (new Rect (Screen.width - 220,Screen.height - 55,100,45), "HP | " + (int)currentHp);
|
||||
}else{
|
||||
GUI.color = new Color(1,1,1, fadeValue);
|
||||
GUI.DrawTexture(new Rect(Screen.width/2 - 13, Screen.height/2 - 13, 26, 26), hitMarkTexture, ScaleMode.StretchToFill );
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator doCameraShake(){
|
||||
//Change shake amount here (Currently its 10)
|
||||
camRot = Quaternion.Euler (Random.Range(-10, 10), Random.Range(-10, 10), 0);
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
camRot = camDefaultRotation;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
fadeValue = Mathf.Lerp(fadeValue, 0, Time.deltaTime*2);
|
||||
fadeValueB = Mathf.Lerp(fadeValueB, 0, Time.deltaTime*2);
|
||||
//Do camera shake effect
|
||||
if(Camera.main)
|
||||
Camera.main.transform.localRotation = Quaternion.Slerp(Camera.main.transform.localRotation, camRot, Time.deltaTime * 15);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d8f700e0f6647640b90d4a36470163d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,118 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//Implementation of Photon Networking system
|
||||
//Remote and local player setup
|
||||
//Player position sync over Network
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class PlayerLocationSync : Photon.MonoBehaviour {
|
||||
|
||||
//Temporary variable
|
||||
[HideInInspector]
|
||||
public string playerName;
|
||||
//This is target fro HeadLookControllerc.cs
|
||||
public Transform lookTarget;
|
||||
public List<GameObject> remoteObjectsToDeactivate;
|
||||
public List<MonoBehaviour> remoteScriptsToDeactivate;
|
||||
public List<GameObject> localObjectsToDeactivate;
|
||||
|
||||
public List<MonoBehaviour> localScriptsToDeactivate;
|
||||
|
||||
CharacterController cc;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
cc = GetComponent<CharacterController>();
|
||||
if(!photonView.isMine){
|
||||
for(int i = 0; i<remoteObjectsToDeactivate.Count;i++){
|
||||
remoteObjectsToDeactivate[i].SetActiveRecursively(false);
|
||||
}
|
||||
for(int a = 0; a<remoteScriptsToDeactivate.Count;a++){
|
||||
//remoteScriptsToDeactivate[a].enabled = false;
|
||||
Destroy(remoteScriptsToDeactivate[a]);
|
||||
}
|
||||
//gameObject.layer = 0;
|
||||
gameObject.tag = "Remote";
|
||||
if(lookTarget.gameObject.active == false){
|
||||
lookTarget.gameObject.active = true;
|
||||
}
|
||||
}else{
|
||||
for(int b = 0; b<localObjectsToDeactivate.Count;b++){
|
||||
localObjectsToDeactivate[b].SetActiveRecursively(false);
|
||||
}
|
||||
for(int c = 0; c<localScriptsToDeactivate.Count;c++){
|
||||
//localScriptsToDeactivate[c].enabled = false;
|
||||
Destroy(localScriptsToDeactivate[c]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Smooth player movement
|
||||
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
|
||||
if (stream.isWriting){
|
||||
//We own this player: send the others our data
|
||||
// stream.SendNext((int)controllerScript._characterState);
|
||||
stream.SendNext(transform.position);
|
||||
stream.SendNext(transform.rotation);
|
||||
if(cc){
|
||||
stream.SendNext(cc.center);
|
||||
stream.SendNext(cc.height);
|
||||
}
|
||||
stream.SendNext(gameObject.name);
|
||||
stream.SendNext(lookTarget.position);
|
||||
stream.SendNext(lookTarget.rotation);
|
||||
}else{
|
||||
//Network player, receive data
|
||||
//controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
|
||||
correctPlayerPos = (Vector3)stream.ReceiveNext();
|
||||
correctPlayerRot = (Quaternion)stream.ReceiveNext();
|
||||
capsulePos = (Vector3)stream.ReceiveNext();
|
||||
capsuleScale = (float)stream.ReceiveNext();
|
||||
PlayerName = (string)stream.ReceiveNext();
|
||||
lookTargetPos = (Vector3)stream.ReceiveNext();
|
||||
lookTargetRot = (Quaternion)stream.ReceiveNext();
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 correctPlayerPos = new Vector3(0, -100, 0); //We lerp towards this
|
||||
private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this
|
||||
private Vector3 capsulePos = Vector3.zero; //We lerp towards this
|
||||
private float capsuleScale = 0; //We lerp towards this
|
||||
private string PlayerName = "";
|
||||
private Vector3 lookTargetPos = Vector3.zero;
|
||||
private Quaternion lookTargetRot = Quaternion.identity;
|
||||
|
||||
void Update(){
|
||||
if (!photonView.isMine){
|
||||
//Update remote player (smooth this, this looks good, at the cost of some accuracy)
|
||||
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 8);
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 8);
|
||||
lookTarget.position = Vector3.Lerp(lookTarget.position, lookTargetPos, Time.deltaTime * 8);
|
||||
lookTarget.rotation = lookTargetRot;
|
||||
|
||||
if(cc.height != capsulePos.y && cc.height != capsuleScale){
|
||||
cc.center = capsulePos;
|
||||
cc.height = capsuleScale;
|
||||
}
|
||||
if(gameObject.name != PlayerName){
|
||||
gameObject.name = PlayerName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReDeactivatePlayerObjects(){
|
||||
if(photonView.isMine){
|
||||
for(int b = 0; b<localObjectsToDeactivate.Count;b++){
|
||||
localObjectsToDeactivate[b].SetActiveRecursively(false);
|
||||
}
|
||||
for(int c = 0; c<localScriptsToDeactivate.Count;c++){
|
||||
//localScriptsToDeactivate[c].enabled = false;
|
||||
Destroy(localScriptsToDeactivate[c]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d733ee8af31407d45882458198509ffa
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,257 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class RoomMultiplayerMenu : Photon.MonoBehaviour {
|
||||
|
||||
public GUISkin guiSkin;
|
||||
public GameObject playerPrefab;
|
||||
public List<Transform> spawnPoints;
|
||||
public GUIStyle style;
|
||||
|
||||
|
||||
[HideInInspector]
|
||||
public bool isPaused;
|
||||
GameObject enableHelper;
|
||||
|
||||
ConnectMenu cm;
|
||||
bool playerList;
|
||||
Resolution[] resolutions;
|
||||
string[] QualityNames;
|
||||
int resolutionIndex = 3;
|
||||
Vector2 scroll;
|
||||
Vector2 scroll2;
|
||||
Vector2 scroll3;
|
||||
|
||||
//Our player spawned
|
||||
GameObject Player;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
cm = GetComponent<ConnectMenu>();
|
||||
isPaused = true;
|
||||
resolutions = Screen.resolutions;
|
||||
resolutionIndex = (resolutions.Length-1)/2;
|
||||
QualityNames = QualitySettings.names;
|
||||
playerList = true;
|
||||
enableHelper = GameObject.FindWithTag("EnableHelper").gameObject;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.Tab) && Player){
|
||||
isPaused = !isPaused;
|
||||
}
|
||||
/*if(!Player){
|
||||
isPaused = true;
|
||||
}*/
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.P)){
|
||||
Screen.fullScreen = !Screen.fullScreen;
|
||||
if(!Screen.fullScreen){
|
||||
Screen.SetResolution(resolutions[resolutionIndex].width, resolutions[resolutionIndex].height, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(isPaused){
|
||||
if(enableHelper.active == true){
|
||||
enableHelper.active = false;
|
||||
}
|
||||
Screen.lockCursor = false;
|
||||
}else{
|
||||
if(enableHelper.active == false){
|
||||
enableHelper.active = true;
|
||||
}
|
||||
Screen.lockCursor = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnGUI(){
|
||||
GUI.Label(new Rect(Screen.width-190, Screen.height-80, 190, 20), " Tab - pause menu", style);
|
||||
if(!isPaused)
|
||||
return;
|
||||
GUI.skin = guiSkin;
|
||||
|
||||
GUI.color = new Color(1, 1, 1, 0.7f);
|
||||
|
||||
if(isPaused){
|
||||
GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 300), MainMenu, "Pause Menu | Room: " + PhotonNetwork.room.name);
|
||||
GUI.Window (1, new Rect (Screen.width/2-240, Screen.height/2 - 95, 150, 100), Resolutions, "Resolution");
|
||||
GUI.Window (2, new Rect (Screen.width/2-85, Screen.height/2 - 95, 150, 100), QualityWindow, "Quality");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainMenu (int windowID) {
|
||||
GUILayout.Space (10);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Box(resolutions[resolutionIndex].width + " x " + resolutions[resolutionIndex].height, GUILayout.Width(150), GUILayout.Height(25));
|
||||
|
||||
GUILayout.Box(QualityNames[QualitySettings.GetQualityLevel ()], GUILayout.Width(150), GUILayout.Height(25));
|
||||
|
||||
|
||||
GUILayout.Space (15);
|
||||
GUILayout.BeginVertical();
|
||||
if(!Player){
|
||||
if(GUILayout.Button("Spawn")){
|
||||
isPaused = false;
|
||||
SpawnPlayer();
|
||||
}
|
||||
}else{
|
||||
if(GUILayout.Button("Resume")){
|
||||
isPaused = false;
|
||||
}
|
||||
}
|
||||
if(GUILayout.Button("Leave Room")){
|
||||
LeaveRoom();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space (55);
|
||||
|
||||
//GUILayout.Label("Objective: Have fun :D");
|
||||
GUILayout.BeginHorizontal();
|
||||
if(playerList){
|
||||
GUI.color = new Color(0, 20, 0, 0.6f);
|
||||
}else{
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
if(GUILayout.Button("Player List", GUILayout.Width(150), GUILayout.Height(25))){
|
||||
playerList = true;
|
||||
}
|
||||
if(!playerList){
|
||||
GUI.color = new Color(0, 20, 0, 0.6f);
|
||||
}else{
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
if(GUILayout.Button("Controls", GUILayout.Width(150), GUILayout.Height(25))){
|
||||
playerList = false;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space (5);
|
||||
GUI.color = Color.white;
|
||||
scroll3 = GUILayout.BeginScrollView(scroll3, GUILayout.Width(480), GUILayout.Height(100));
|
||||
if(!playerList){
|
||||
//Show controls
|
||||
GUI.color = new Color(20, 20,0, 0.6f);
|
||||
GUILayout.Label("Tab - Pause Menu");
|
||||
GUILayout.Label("P - Fullscreen");
|
||||
GUILayout.Label("T - Chat / Enter - send");
|
||||
GUILayout.Label("C - crouch");
|
||||
GUILayout.Label("Left Ctrl - prone");
|
||||
GUILayout.Label("LMB - fire");
|
||||
GUILayout.Label("RMB - aim");
|
||||
GUILayout.Label("F - weapon pick up");
|
||||
GUILayout.Label("R - reload");
|
||||
GUILayout.Label("Left Shift - run");
|
||||
GUILayout.Label("Space - jump");
|
||||
GUILayout.Label("1/2 - weapon change");
|
||||
GUILayout.Label("While selected STW-25 press G for flashlight");
|
||||
}else{
|
||||
//Show player list***
|
||||
GUI.color = new Color(1,1,1,0.8f);
|
||||
foreach(PhotonPlayer player in PhotonNetwork.playerList){
|
||||
if(PhotonNetwork.player.name == player.name){
|
||||
GUI.color = Color.yellow;
|
||||
}else{
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
GUILayout.BeginHorizontal("box");{
|
||||
GUILayout.Label(player.name, style);
|
||||
if(PhotonNetwork.player.name == player.name){
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.Label("Ping: " + PhotonNetwork.GetPing().ToString(), style);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();}
|
||||
}
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
void Resolutions( int windowID){
|
||||
GUI.BringWindowToFront(windowID);
|
||||
GUILayout.Space (10);
|
||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(140), GUILayout.Height(65));
|
||||
GUILayout.BeginVertical();
|
||||
for(int a = 0; a < resolutions.Length; a++){
|
||||
if(resolutions[a].width == Screen.width && resolutions[a].height == Screen.height){
|
||||
GUI.color = new Color(0, 20, 20, 0.6f);
|
||||
}else{
|
||||
GUI.color = new Color(20, 20, 20, 0.6f);
|
||||
}
|
||||
if(GUILayout.Button(resolutions[a].width + " x " + resolutions[a].height)){
|
||||
resolutionIndex = a;
|
||||
if(Screen.fullScreen){
|
||||
Screen.SetResolution (resolutions[resolutionIndex].width,resolutions[resolutionIndex].height, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
void QualityWindow(int windowID){
|
||||
GUI.BringWindowToFront(windowID);
|
||||
GUILayout.Space (10);
|
||||
scroll2 = GUILayout.BeginScrollView(scroll2, GUILayout.Width(140), GUILayout.Height(65));
|
||||
GUILayout.BeginVertical();
|
||||
for (var i = 0; i < QualityNames.Length; i++){
|
||||
if(QualityNames[i] == QualityNames[QualitySettings.GetQualityLevel ()]){
|
||||
GUI.color = new Color(0, 20, 20, 0.6f);
|
||||
}else{
|
||||
GUI.color = new Color(20, 20, 20, 0.6f);
|
||||
}
|
||||
if (GUILayout.Button (QualityNames[i]))
|
||||
QualitySettings.SetQualityLevel (i, true);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
void SpawnPlayer(){
|
||||
if(Player){
|
||||
Destroy(Player);
|
||||
}
|
||||
enableHelper.active = true;
|
||||
//Spawn our player
|
||||
int temp;
|
||||
temp = Random.Range(0, spawnPoints.Count);
|
||||
Player = PhotonNetwork.Instantiate(playerPrefab.name, spawnPoints[temp].position, spawnPoints[temp].rotation, 0);
|
||||
Player.name = cm.playerName;
|
||||
transform.GetChild(0).gameObject.active = false;
|
||||
}
|
||||
|
||||
void LeaveRoom(){
|
||||
if(PhotonNetwork.connected){
|
||||
PhotonNetwork.RemoveAllBufferedMessages();
|
||||
PhotonNetwork.RemoveRPCs();
|
||||
cm.enabled = true;
|
||||
cm.connectingToRoom = true;
|
||||
cm.fadeDir = -1;
|
||||
PhotonNetwork.LeaveRoom();
|
||||
this.enabled = false;
|
||||
transform.GetChild(0).gameObject.active = true;
|
||||
isPaused = false;
|
||||
Player = null;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisconnectedFromPhoton(){
|
||||
print ("Disconnected from Photon");
|
||||
//Something wrong with connection - go to main menu
|
||||
cm.enabled = true;
|
||||
cm.fadeDir = -1;
|
||||
transform.GetChild(0).gameObject.active = true;
|
||||
isPaused = false;
|
||||
Player = null;
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d938a3bcdb2d2b34baa7935c9313b949
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,30 @@
|
||||
//This script is used to catch fire messages from WeaponScript.js
|
||||
//Then pass those messages to WeaponSync.cs
|
||||
//Should be attached to every wepaon with WeaponScript.js
|
||||
|
||||
#pragma strict
|
||||
|
||||
var thirdPersonWeapon : GameObject;
|
||||
private var weapScript : WeaponScript;
|
||||
|
||||
function Awake(){
|
||||
weapScript = gameObject.GetComponent.<WeaponScript>();
|
||||
}
|
||||
|
||||
function Fire(){
|
||||
if(thirdPersonWeapon.active == false){
|
||||
thirdPersonWeapon.active = true;
|
||||
}
|
||||
if(weapScript.GunType == weapScript.gunType.MACHINE_GUN){
|
||||
thirdPersonWeapon.SendMessage("syncMachineGun", weapScript.errorAngle);
|
||||
}
|
||||
if(weapScript.GunType == weapScript.gunType.SHOTGUN){
|
||||
thirdPersonWeapon.SendMessage("syncShotGun", weapScript.ShotGun.fractions);
|
||||
}
|
||||
if(weapScript.GunType == weapScript.gunType.GRENADE_LAUNCHER){
|
||||
thirdPersonWeapon.SendMessage("syncGrenadeLauncher", weapScript.grenadeLauncher.initialSpeed);
|
||||
}
|
||||
if(weapScript.GunType == weapScript.gunType.KNIFE){
|
||||
thirdPersonWeapon.SendMessage("syncKnife");
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e5ae708cced4f04da5928c8d1a80478
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,130 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//This script is used to controll third person weapons over network
|
||||
// It receives messages from WeaponScript and make effect that remote player is shooting for others
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[RequireComponent (typeof (AudioSource))]
|
||||
[RequireComponent (typeof (PhotonView))]
|
||||
|
||||
public class WeaponSync : Photon.MonoBehaviour {
|
||||
//We have 4 possible types of weapons (MACHINE_GUN, GRENADE_LAUNCHER, SHOTGUN, KNIFE)
|
||||
//So we will have 4 functions to receive message from each of those types
|
||||
|
||||
public Transform firePoint;
|
||||
//Assign this if we synchronize MACHINE_GUN or SHOTGUN or KNIFE
|
||||
public GameObject bullet;
|
||||
public Renderer muzzleFlash;
|
||||
//Assign this if we synchronize GRENADE_LAUNCHER
|
||||
public Rigidbody projectile;
|
||||
|
||||
public AudioClip fireAudio;
|
||||
|
||||
public Collider ignoreCollider;
|
||||
|
||||
//MACHINE GUN type weapons sync
|
||||
void syncMachineGun(float errorAngle){
|
||||
photonView.RPC("machineGunShot", PhotonTargets.Others, errorAngle);
|
||||
}
|
||||
|
||||
[RPC]
|
||||
IEnumerator machineGunShot(float errorAngle){
|
||||
Quaternion oldRotation = firePoint.rotation;
|
||||
firePoint.rotation = Quaternion.Euler(Random.insideUnitSphere * errorAngle) * firePoint.rotation;
|
||||
Instantiate (bullet, firePoint.position, firePoint.rotation);
|
||||
firePoint.rotation = oldRotation;
|
||||
//Play fire sound
|
||||
audio.clip = fireAudio;
|
||||
audio.Play();
|
||||
//Muzzle flash
|
||||
if(muzzleFlash){
|
||||
muzzleFlash.renderer.enabled = true;
|
||||
yield return new WaitForSeconds(0.04f);
|
||||
muzzleFlash.renderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//SHOTGUN type weapons sync
|
||||
void syncShotGun(int fractions){
|
||||
photonView.RPC("shotGunShot", PhotonTargets.Others, fractions);
|
||||
}
|
||||
|
||||
[RPC]
|
||||
IEnumerator shotGunShot(int fractions){
|
||||
for (int i = 0;i < fractions; i++) {
|
||||
Quaternion oldRotation = firePoint.rotation;
|
||||
firePoint.rotation = Quaternion.Euler(Random.insideUnitSphere * 3) * firePoint.rotation;
|
||||
Instantiate (bullet, firePoint.position, firePoint.rotation);
|
||||
firePoint.rotation = oldRotation;
|
||||
}
|
||||
//Play fire sound
|
||||
audio.clip = fireAudio;
|
||||
audio.Play();
|
||||
//Muzzle flash
|
||||
if(muzzleFlash){
|
||||
muzzleFlash.renderer.enabled = true;
|
||||
yield return new WaitForSeconds(0.04f);
|
||||
muzzleFlash.renderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//GRENADE LAUNCHER type weapon sync
|
||||
void syncGrenadeLauncher(float initialSpeed){
|
||||
photonView.RPC("grenadeLauncherShot", PhotonTargets.Others, initialSpeed);
|
||||
}
|
||||
|
||||
[RPC]
|
||||
void grenadeLauncherShot(float initialSpeed){
|
||||
// create a new projectile, use the same position and rotation as the Launcher.
|
||||
Rigidbody instantiatedProjectile = Instantiate(projectile, firePoint.position, firePoint.rotation) as Rigidbody;
|
||||
// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
|
||||
//instantiatedProjectile.velocity = transform.TransformDirection(new Vector3 (initialSpeed, 0, 0));
|
||||
instantiatedProjectile.AddForce(instantiatedProjectile.transform.forward * initialSpeed*50);
|
||||
// Ignore collisions between the missile and the character controller
|
||||
foreach(Collider c in transform.root.GetComponentsInChildren<Collider>())
|
||||
Physics.IgnoreCollision(instantiatedProjectile.collider, c);
|
||||
|
||||
audio.clip = fireAudio;
|
||||
audio.Play();
|
||||
}
|
||||
|
||||
void syncKnife(){
|
||||
photonView.RPC("knifeOneHit", PhotonTargets.Others);
|
||||
}
|
||||
|
||||
[RPC]
|
||||
void knifeOneHit(){
|
||||
audio.clip = fireAudio;
|
||||
audio.Play();
|
||||
}
|
||||
|
||||
void Awake(){
|
||||
if(muzzleFlash){
|
||||
muzzleFlash.renderer.enabled = false;
|
||||
}
|
||||
audio.playOnAwake = false;
|
||||
ignoreCollider = transform.root.collider;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if(photonView.isMine){
|
||||
gameObject.active = true;
|
||||
if(gameObject.renderer != null){
|
||||
gameObject.renderer.enabled = false;
|
||||
}else{
|
||||
Renderer[] renderers = GetComponentsInChildren<Renderer>();
|
||||
foreach(Renderer r in renderers){
|
||||
r.enabled = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(firePoint){
|
||||
firePoint.gameObject.active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d73886ae94c434d47955a608e859a39b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,87 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//This script is used to show on screen who kileld who
|
||||
//Script should be attached to object with tag "Network"
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class WhoKilledWho : Photon.MonoBehaviour {
|
||||
|
||||
public GUISkin guiSkin;
|
||||
|
||||
public struct WhoKillWho {
|
||||
//Name of the player who killed other player
|
||||
public string killer { get; set; }
|
||||
//Name of the player who got killed
|
||||
public string killed { get; set; }
|
||||
|
||||
public WhoKillWho(string string1, string string2){
|
||||
killer = string1;
|
||||
killed = string2;
|
||||
}
|
||||
|
||||
}
|
||||
public List<WhoKillWho> whoKillWho = new List<WhoKillWho>();
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
GUI.skin = guiSkin;
|
||||
GUILayout.BeginArea(new Rect(Screen.width/2, 60, Screen.width/2, 400));
|
||||
//Show kill notificatin list
|
||||
foreach(WhoKillWho wkw in whoKillWho){
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
//Green
|
||||
GUI.color = new Color(0, 1, 0, 0.65f);
|
||||
GUILayout.Label(wkw.killer);
|
||||
GUILayout.Space(5);
|
||||
//White
|
||||
GUI.color = new Color(1, 1, 1, 0.65f);
|
||||
GUILayout.Label("killed");
|
||||
GUILayout.Space(5);
|
||||
//Red
|
||||
GUI.color = new Color(1, 0, 0, 0.65f);
|
||||
GUILayout.Label(wkw.killed);
|
||||
GUILayout.Space(10);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
//Receive message and update List
|
||||
void AddKillNotification(string killed){
|
||||
photonView.RPC("networkAddMessage", PhotonTargets.All, PhotonNetwork.playerName, killed);
|
||||
}
|
||||
|
||||
[RPC]
|
||||
void networkAddMessage(string killer, string killed){
|
||||
whoKillWho.Add(new WhoKillWho(killer, killed));
|
||||
//Message count limit
|
||||
if (whoKillWho.Count > 5)
|
||||
whoKillWho.RemoveAt(0);
|
||||
}
|
||||
|
||||
void OnLeftRoom(){
|
||||
whoKillWho.Clear();
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
void OnJoinedRoom(){
|
||||
this.enabled = true;
|
||||
}
|
||||
void OnCreatedRoom(){
|
||||
this.enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3356fb7579e547e48a02b8ab8b8129a9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user