Hey Guys,
Sniper here
I am making a Multiplayer FPS and i have nearly done everything, I just have to complete a few things and these are one of them.
Basically I need to make a choose equipment screen, for before you press the spawn button. I was wondering how you would go about doing that, i’ll show you my player manager script which holds all the weapon info and such.
using UnityEngine;
using System.Collections;
public class PlayerManager : MonoBehaviour
{
public MPPlayer thisplayer;
public PlayerController Controller;
public Transform ControllerTransform;
public GameObject OutsideView;
public Vector3 CurrentPosition;
public Quaternion CurrentRotation;
void Start()
{
DontDestroyOnLoad(gameObject);
OutsideView.SetActiveRecursively(false);
ControllerTransform.gameObject.SetActiveRecursively(false);
thisplayer = MultiplayerManager.GetMPPlayer(networkView.owner);
thisplayer.PlayerManager = this;
}
void FixedUpdate()
{
if(networkView.isMine)
{
CurrentPosition = ControllerTransform.position;
CurrentRotation = ControllerTransform.rotation;
}
else
{
ControllerTransform.position = CurrentPosition;
ControllerTransform.rotation = CurrentRotation;
}
}
void OnSerializeNeworkView(BitStream stream, NetworkMessageInfo info)
{
if(stream.isWriting)
{
stream.Serialize(ref CurrentPosition);
stream.Serialize(ref CurrentRotation);
}
else
{
stream.Serialize(ref CurrentPosition);
stream.Serialize(ref CurrentRotation);
}
}
void HandleBulletDamage(int damage)
{
if(Network.isServer)
Server_HandleBulletDamage(damage);
else
networkView.RPC("Server_HandleBulletDamage", RPCMode.Server, damage);
}
[RPC]
public void Server_HandleBulletDamage(int damage)
{
thisplayer.PlayerHealth -= damage;
if(thisplayer.PlayerHealth <= 0)
{
thisplayer.PlayerIsAlive = false;
thisplayer.PlayerHealth = 0;
networkView.RPC("Client_PlayerDead", RPCMode.All);
}
else
{
}
}
[RPC]
public void Client_PlayerDead()
{
OutsideView.SetActiveRecursively(false);
if(networkView.isMine)
{
ControllerTransform.gameObject.SetActiveRecursively(false);
}
}
[RPC]
public void Client_PlayerAlive()
{
OutsideView.SetActiveRecursively(true);
if(networkView.isMine)
{
ControllerTransform.gameObject.SetActiveRecursively(true);
}
else
{
OutsideView.SetActiveRecursively(true);
}
}
}
thanks guys for your help and if you need anymore information just ask:)
~Sniper
sorry i ment to post the player controller here it is with all the stuff
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerController : MonoBehaviour
{
public static PlayerController instance;
public CharacterController CharCont;
public CharacterMotor CharMotor;
public Transform WalkAnimationHolder;
public Transform JumpAnimationHolder;
public Transform ADSHolder;
public Transform SwayHolder;
public Transform RecoilHolder;
public Transform RecoilHolderCamera;
public Transform PlayerCamera;
public WalkingState walkingstate = WalkingState.Idle;
public float VelocityMagnitude;
public float WalkSpeed;
public float RunSpeed;
public WeaponInfo WeaponInfo;
public bool WasStanding;
//player variables
public bool IsAiming;
public WeaponInfo CurrentWeapon;
public List<WeaponInfo> WeaponList = new List<WeaponInfo>();
public Vector3 CurrentRecoil1;
public Vector3 CurrentRecoil2;
public Vector3 CurrentRecoil3;
public Vector3 CurrentRecoil4;
private float shoottime = 0;
void Start()
{
CurrentWeapon = WeaponList[0];
instance = this;
}
public void Update()
{
ShootController();
}
public void FixedUpdate()
{
AnimationController();
SwayController();
SpeedController();
RecoilController();
ADSController();
VelocityMagnitude = CharCont.velocity.magnitude;
}
public void SpeedController()
{
if((Input.GetAxis ("Horizontal") != 0 || Input.GetAxis ("Vertical") != 0) VelocityMagnitude > 0)
{
if(Input.GetButton ("Sprint"))
{
walkingstate = WalkingState.Running;
CharMotor.movement.maxForwardSpeed = RunSpeed;
CharMotor.movement.maxSidewaysSpeed = RunSpeed;
CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2;
}
else
{
walkingstate = WalkingState.Walking;
CharMotor.movement.maxForwardSpeed = WalkSpeed;
CharMotor.movement.maxSidewaysSpeed = WalkSpeed;
CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2;
}
}
else
{
walkingstate = WalkingState.Idle;
}
}
public void AnimationController()
{
if(WasStanding !CharCont.isGrounded)
{
WasStanding = false;
JumpAnimationHolder.animation.Play("Jump");
}
else if(!WasStanding CharCont.isGrounded)
{
WasStanding = true;
JumpAnimationHolder.animation.Play("Land");
}
if(walkingstate == WalkingState.Running)
{
WalkAnimationHolder.animation["Run"].speed = VelocityMagnitude / RunSpeed;
WalkAnimationHolder.animation.CrossFade("Run", 0.2f);
}
else if(walkingstate == WalkingState.Walking)
{
WalkAnimationHolder.animation["Walk"].speed = VelocityMagnitude / WalkSpeed;
WalkAnimationHolder.animation.CrossFade("Walk", 0.2f);
}
else
{
WalkAnimationHolder.animation.CrossFade("Idle", 0.2f);
}
}
public void SwayController()
{
}
public void ShootController()
{
if(Input.GetButton("Fire1") walkingstate != WalkingState.Running)
{
if(shoottime <= Time.time)
{
shoottime = Time.time + CurrentWeapon.FireRate;
CurrentRecoil1 += new Vector3(CurrentWeapon.RecoilRotation.x, Random.Range(-CurrentWeapon.RecoilRotation.y, CurrentWeapon.RecoilRotation.y));
CurrentRecoil3 += new Vector3(Random.Range (-CurrentWeapon.RecoilKickBack.x, CurrentWeapon.RecoilKickBack.x), Random.Range (-CurrentWeapon.RecoilKickBack.y, CurrentWeapon.RecoilKickBack.y), CurrentWeapon.RecoilKickBack.z);
}
}
}
public void RecoilController()
{
CurrentRecoil1 = Vector3.Lerp(CurrentRecoil1, Vector3.zero, 0.1f);
CurrentRecoil2 = Vector3.Lerp(CurrentRecoil2, CurrentRecoil1, 0.1f);
CurrentRecoil3 = Vector3.Lerp(CurrentRecoil3, Vector3.zero, 0.1f);
CurrentRecoil4 = Vector3.Lerp(CurrentRecoil4, CurrentRecoil3, 0.1f);
RecoilHolder.localEulerAngles = CurrentRecoil2;
RecoilHolder.localPosition = CurrentRecoil4;
RecoilHolderCamera.localEulerAngles = CurrentRecoil2 / 1.2f;
}
public void ADSController()
{
if(Input.GetButton("Fire2"))
{
IsAiming = true;
ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].adsPosition, 0.25f);
PlayerCamera.camera.fieldOfView = Mathf.Lerp(PlayerCamera.camera.fieldOfView, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].fov, 0.25f);
}
else{
IsAiming = false;
ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, Vector3.zero, 0.25f);
PlayerCamera.camera.fieldOfView = Mathf.Lerp(PlayerCamera.camera.fieldOfView, 60, 0.25f);
}
}
}
public enum WalkingState
{
Idle,
Walking,
Running
}
[System.Serializable]
public class WeaponInfo
{
public string Name = "Weapon";
public float FireRate = 0.1f;
public Transform WeaponTransform;
public Vector3 RecoilRotation;
public Vector3 RecoilKickBack;
public Transform SpawnPoint;
public int CurrentScope;
public List<WeaponScope> Scopes = new List<WeaponScope>();
}
[System.Serializable]
public class WeaponScope
{
public string name;
public float fov;
public Vector3 adsPosition;
public Transform scopeTransform;
}
[System.Serializable]
public class WeaponFrontAttachment
{
public string name;
public Transform frontWeaponTransform;
}
Cmon guys i really need to get this done
not many people with help with something that was made by following a tut…