@@ -3,6 +3,8 @@

public class Backpack : MonoBehaviour {

public GameObject hand;

private PlayerController player;
private GameObject body;
private Vector3 oldPosition;
@@ -16,7 +18,7 @@ public class Backpack : MonoBehaviour {
// Update is called once per frame
void Update () {
if (player.gameplay) {
this.transform.localPosition = new Vector3(0, 0.25f, -0.68f);
this.transform.localPosition = new Vector3(0, 2.17f, -0.68f);
}
if (player.equipment) {
this.transform.position = new Vector3(body.transform.position.x + body.transform.forward.x, 0.25f, body.transform.position.z + body.transform.forward.z);
@@ -26,6 +28,7 @@ public class Backpack : MonoBehaviour {
void OnMouseOver()
{
if (player.equipment) {
//hand.transform.LookAt(this.transform.position);
print("Backpack");
}
}
@@ -0,0 +1,68 @@
using UnityEngine;
using System.Collections;

public class BodyCollision : MonoBehaviour {

private PlayerController player;
private HandController hand;
private Weapon collidingWeapon;
private bool weaponIsActive;

// Use this for initialization
void Start () {
player = GetComponentInParent<PlayerController> ();
hand = GetComponentInChildren<HandController> ();
}

// Update is called once per frame
void Update () {
if (weaponIsActive)
PickUp (collidingWeapon);
}

void OnTriggerEnter(Collider col)
{
if (col.tag == "Weapon") {
//Debug.Log (player.CompareWeapons (col.GetComponent<Weapon> (), player.currentWeapon));
col.GetComponent<Weapon>().isActive = true;
weaponIsActive = true;
//player.pickUp = true;
collidingWeapon = col.GetComponent<Weapon>();
col.GetComponent<Weapon>().buttonImage.transform.position = new Vector3(col.transform.position.x, col.transform.position.y + 0.5f, col.transform.position.z);
}
}

void OnTriggerExit(Collider col)
{
if (col.tag == "Weapon") {
col.GetComponent<Weapon>().isActive = false;
weaponIsActive = false;
//player.pickUp = false;
collidingWeapon = null;
}
}

void PickUp(Weapon w){
if (Input.GetKeyDown (KeyCode.E) && !player.pickUp) {
//weapon transformation
w.transform.position = hand.weaponPivot.transform.position;
w.transform.Translate(new Vector3(0.25f, 0, 0));
w.transform.rotation = hand.weaponPivot.transform.rotation;
w.transform.Rotate(new Vector3(270, 0, 0));
w.transform.SetParent(hand.weaponPivot.transform);
w.WeaponOriginalRotation = w.transform.rotation;
///////////////////////
w.isActive = false;
w.GetComponent<BoxCollider>().enabled = false;

weaponIsActive = false;

//hand transformation
hand.transform.Rotate(-90, 0, 0);
/////////////////////

player.pickUp = true;
player.pickedUpWeapon = w;
}
}
}
@@ -11,6 +11,7 @@ public class CameraController2 : MonoBehaviour {
private int equipmentIdle = Animator.StringToHash("Base Layer.EquipmentIdle");
private int gameplayHash = Animator.StringToHash("Gameplay");
private int idleHash = Animator.StringToHash("Base Layer.Idle");
private int pickUpHash = Animator.StringToHash("PickingUp");

// Use this for initialization
void Start () {
@@ -37,6 +38,10 @@ public class CameraController2 : MonoBehaviour {
myAnimator.ResetTrigger(gameplayHash);
myAnimator.SetTrigger(equipmentHash);
}
if (player.pickUp) {
myAnimator.ResetTrigger(gameplayHash);
myAnimator.SetTrigger(pickUpHash);
}
}

void CameraMovement(){
@@ -3,6 +3,8 @@

public class Equipment : MonoBehaviour {

public GameObject hand;

private PlayerController player;

// Use this for initialization
@@ -18,6 +20,7 @@ public class Equipment : MonoBehaviour {
void OnMouseOver()
{
if (player.equipment) {
//hand.transform.LookAt(this.transform.position);
print ("Check Equipment");
}
}
@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;

public class HandController : MonoBehaviour {

public PlayerController player;
public GameObject defaultLookAt;
public GameObject weaponPivot;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
if (player.gameplay) {
//this.transform.LookAt(defaultLookAt.transform.position);
}
}
}
@@ -8,8 +8,6 @@ public class HeadController : MonoBehaviour {
public bool itemDetected;

public float fieldOfViewAngle = 60.0f;

//TODO: Blokada rotacji głowy (żeby była naturalna)

// Use this for initialization
void Start () {
@@ -7,6 +7,9 @@ public class PlayerController : MonoBehaviour {
public float turningSpeed = 30;
public bool gameplay;
public bool equipment;
public bool pickUp;
public Weapon currentWeapon;
public Weapon pickedUpWeapon;

private float horizontal;
private float vertical;
@@ -26,8 +29,10 @@ public class PlayerController : MonoBehaviour {

// Use this for initialization
void Start () {
currentWeapon = null;
gameplay = true;
equipment = false;
pickUp = false;
pivot = GameObject.Find ("CameraPivot");
body = GameObject.Find ("Body");
head = GameObject.Find ("Head");
@@ -37,14 +42,20 @@ public class PlayerController : MonoBehaviour {

// Update is called once per frame
void Update () {
OpenEquipment ();
if (!pickUp) {
OpenEquipment ();
}
if (gameplay) {
Movement();
MouseControl();
}
if (equipment) {
gameplay = false;
}
if (pickUp) {
gameplay = false;
ObserveItem(pickedUpWeapon);
}
}

void OpenEquipment(){
@@ -85,6 +96,21 @@ public class PlayerController : MonoBehaviour {
newForward = new Vector3 (pivot.transform.forward.x, 0, pivot.transform.forward.z);
}

public void ObserveItem(Weapon w){
Debug.Log (CompareWeapons (w, currentWeapon));

w.WeaponRotationX += Input.GetAxis ("Mouse X") * turningSpeed;
w.WeaponRotationY += Input.GetAxis ("Mouse Y") * turningSpeed;

w.WeaponRotationX = ClampAngle (w.WeaponRotationX, -30.0f, 30.0f);
w.WeaponRotationY = ClampAngle (w.WeaponRotationY, -30.0f, 30.0f);

Quaternion xQuaternion = Quaternion.AngleAxis (w.WeaponRotationX, -Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (w.WeaponRotationY, Vector3.forward);

w.transform.localRotation = w.WeaponOriginalRotation * xQuaternion * yQuaternion;
}

float ClampAngle(float angle, float min, float max)
{
if (angle < -360F)
@@ -93,4 +119,23 @@ float ClampAngle(float angle, float min, float max)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}

//zrobić komparator dla trzech sztuk broni
public string CompareWeapons(Weapon weapon, Weapon currentWeapon)
{
string s = "";
if (currentWeapon != null) {

if (currentWeapon.damage > weapon.damage) {
s = weapon.name + " deals less damage than " + currentWeapon.name;
} else if (currentWeapon.damage == weapon.damage) {
s = weapon.name + " deals same amount of damage as " + currentWeapon.name;
} else if (currentWeapon.damage < weapon.damage) {
s = weapon.name + " deals more damage than " + currentWeapon.name;
}
} else {
s = "You currently have " + "0" + " weapons. Take it.";
}
return s;
}
}
@@ -0,0 +1,15 @@
using UnityEngine;
using System.Collections;

public class UI : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
this.transform.forward = new Vector3 (Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z);
}
}
@@ -0,0 +1,58 @@
using UnityEngine;
using System.Collections;

public class Weapon : MonoBehaviour {

public string name;
public int damage;
public GameObject[] elements;

public UnityEngine.UI.Image buttonImage;
public bool isActive;

private Quaternion weaponOriginalRotation;
private float weaponRotationX = 0;
private float weaponRotationY = 0;

public Quaternion WeaponOriginalRotation {
set {
weaponOriginalRotation = value;
}
get {
return weaponOriginalRotation;
}
}

public float WeaponRotationX {
set {
weaponRotationX = value;
}
get {
return weaponRotationX;
}
}

public float WeaponRotationY {
set {
weaponRotationY = value;
}
get {
return weaponRotationY;
}
}

// Use this for initialization
void Start () {
buttonImage.enabled = false;
isActive = false;
}

// Update is called once per frame
void Update () {
if (isActive) {
buttonImage.enabled = true;
}
else
buttonImage.enabled = false;
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
@@ -17,7 +17,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Assembly-CSharp.csproj
Policies = $0
$0.TextStylePolicy = $1
@@ -17,7 +17,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Assembly-CSharp.csproj
Policies = $0
$0.TextStylePolicy = $1
@@ -1,13 +1,17 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\Equipment.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\BodyCollision.cs">
<Files>
<File FileName="Assets\Scripts\Backpack.cs" Line="29" Column="4" />
<File FileName="Assets\Scripts\HeadController.cs" Line="34" Column="56" />
<File FileName="Assets\Scripts\BodyCollision.cs" Line="49" Column="41" />
<File FileName="Assets\Scripts\Backpack.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\PlayerController.cs" Line="105" Column="70" />
<File FileName="Assets\Scripts\Weapon.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\HeadController.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\CameraController2.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\PlayerController.cs" Line="95" Column="3" />
<File FileName="Assets\Scripts\Raycasting.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\Equipment.cs" Line="10" Column="12" />
<File FileName="Assets\Scripts\Equipment.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\HandController.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\UI.cs" Line="1" Column="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Binary file not shown.
Binary file not shown.