Commit 3b2d24be authored by kgingras's avatar kgingras
Browse files

networkd changes

parent 6c1ef188
using UnityEngine;
using UnityEngine.Networking;
public class PlayerSetup : NetworkBehaviour {
[SerializeField]
Behaviour[] componentsToDisable;//disable other cameras and controllers if not on network
Camera sceneCamera;
void Start(){
if(!isLocalPlayer){
DisableComponents();
AssignToLayer("Remote");
}
else{
sceneCamera = Camera.main;
if(sceneCamera != null){
sceneCamera.gameObject.SetActive(false);
}
AssignToLayer("Local");
}
RegisterPlayer();
PreStartClient ();
}
public override void PreStartClient(){
GetComponent<NetworkAnimator> ().SetParameterAutoSend (0, true);
}
void SetPositions(){
NetworkTransformChild[] childrenPos = GetComponentsInChildren<NetworkTransformChild>();
foreach (NetworkTransformChild child in childrenPos) {
child.target.localPosition = child.targetSyncPosition;
child.target.localRotation = child.targetSyncRotation3D;
}
}
void RegisterPlayer(){
string _Id = "Player" + GetComponent<NetworkIdentity>().netId;
transform.name = _Id;
}
void AssignToLayer(string layer){
gameObject.layer = LayerMask.NameToLayer(layer);
}
void DisableComponents(){
for (int i = 0; i < componentsToDisable.Length; i++){
componentsToDisable[i].enabled = false;
}
}
void OnDisable(){
if(sceneCamera!= null){
sceneCamera.gameObject.SetActive(true);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 648f56b065ea9a0459eff2e376db085d
timeCreated: 1455384001
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -10,18 +10,22 @@ public class BallHandler : MonoBehaviour {
public LayerMask myMask;
public bool handgun = true;
public float shootSpeed;
public float swapSpeed = 2f;
public Camera _Camera;
public GameObject equippedGun;
public GameObject handGunPrefab;
public GameObject riflePrefab;
public GameObject bulletPrefab;
public GameObject GunPos;
public GameObject backPos;
public GameObject hipPos;
GameObject _handgun;
GameObject _rifle;
public GameObject _handgun;
public GameObject _rifle;
Transform _GunTrans;
Transform _RifleBackTrans;
Transform _HandgunHipTrans;
Handle handleScript;
float pickUpCd = 1f;
......@@ -38,11 +42,16 @@ public class BallHandler : MonoBehaviour {
anim = gameObject.GetComponent<Animator>();
anim.SetBool("Handgun", handgun);
anim.SetFloat("Speed", 0);
// _GunTrans.position = Vector3.zero;
// _GunTrans.rotation = Quaternion.Euler(Vector3.zero);
//
// _RifleBackTrans.position = new Vector3(-0.1f,0.05f,0);
// _RifleBackTrans.rotation = Quaternion.Euler(new Vector3(60,90,0));
//
// _HandgunHipTrans.position = Vector3.zero;
// _HandgunHipTrans.rotation = Quaternion.Euler( new Vector3(300,100,180));
_rifle = (GameObject)Instantiate(riflePrefab, backPos.transform.position, Quaternion.identity);
_handgun = (GameObject)Instantiate(handGunPrefab, GunPos.transform.position, Quaternion.identity);
SwitchToHandgun();
}
......@@ -63,7 +72,7 @@ public class BallHandler : MonoBehaviour {
x = Screen.width/2;
y = Screen.height/2;
ray = Camera.main.ScreenPointToRay(new Vector3(x,y,1));
ray = _Camera.ScreenPointToRay(new Vector3(x,y,1));
Physics.Raycast(ray, out hit, Mathf.Infinity, myMask);
......@@ -78,6 +87,23 @@ public class BallHandler : MonoBehaviour {
}
}
//lerp gun positions for network
// if (handgun) {
// _handgun.transform.localPosition = Vector3.Lerp (_handgun.transform.localPosition, _GunTrans.position, swapSpeed * Time.deltaTime);
// _handgun.transform.localRotation = Quaternion.Lerp (_handgun.transform.localRotation, _GunTrans.rotation, swapSpeed * Time.deltaTime);
//
//
// _rifle.transform.localPosition = Vector3.Lerp (_rifle.transform.localPosition, _RifleBackTrans.position, swapSpeed * Time.deltaTime);
// _rifle.transform.localRotation = Quaternion.Lerp (_rifle.transform.localRotation, _RifleBackTrans.rotation, swapSpeed * Time.deltaTime);
// } else {
// _handgun.transform.localPosition = Vector3.Lerp (_handgun.transform.localPosition, _HandgunHipTrans.position, swapSpeed * Time.deltaTime);
// _handgun.transform.localRotation = Quaternion.Lerp (_handgun.transform.localRotation, _HandgunHipTrans.rotation, swapSpeed * Time.deltaTime);
//
//
// _rifle.transform.localPosition = Vector3.Lerp (_rifle.transform.localPosition, _GunTrans.position, swapSpeed * Time.deltaTime);
// _rifle.transform.localRotation = Quaternion.Lerp (_rifle.transform.localRotation, _GunTrans.rotation, swapSpeed * Time.deltaTime);
// }
}
......
......@@ -30,7 +30,7 @@ public class MouseOrbitC : MonoBehaviour {
y = angles.x;
CCscript = GameObject.Find("Capsule").GetComponent<CapsuleController>();
CCscript = gameObject.transform.parent.GetComponent<CapsuleController>();
// Make the rigid body not change rotation
}
......
......@@ -31,7 +31,7 @@ public class ThirdPersonAnimator : MonoBehaviour {
// Use this for initialization
void Start () {
m_Animator = GetComponent<Animator>();
CCscript = GameObject.Find("Capsule").GetComponent<CapsuleController>();
CCscript = gameObject.GetComponent<CapsuleController>();
m_Rigidbody = GetComponent<Rigidbody>();
m_Capsule = GetComponent<CapsuleCollider>();
......
......@@ -14,7 +14,9 @@ public class bullet : MonoBehaviour {
}
void OnCollisionEnter(Collision coll){
if (coll.gameObject.tag == "Team1" || coll.gameObject.tag == "Team2") {
Debug.Log(coll.gameObject.name + " was hit");
}
Destroy(gameObject);
}
}
fileFormatVersion: 2
guid: 8af9a4bb031db5f4ba8277c4adf43af3
timeCreated: 1455383234
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment