test
testing
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4eeea35e03e79040b82063b242147af
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,121 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
@CustomEditor (WeaponScript)
|
||||
|
||||
class WeaponScriptEditor extends Editor {
|
||||
//var gunTipo = target.gunType.MACHINE_GUN;
|
||||
|
||||
|
||||
public function OnInspectorGUI () {
|
||||
|
||||
var script = target as WeaponScript;
|
||||
var allowSceneObjects : boolean = !EditorUtility.IsPersistent(script);
|
||||
|
||||
//Variable that allow assign scene objects *New*
|
||||
gunTipo = script.GunType;
|
||||
|
||||
script.GunType = EditorGUILayout.EnumPopup(" Gun Type:", script.GunType);
|
||||
script.weaponName = EditorGUILayout.TextField(" Weapon Name:", script.weaponName);
|
||||
|
||||
if(script.GunType != script.gunType.KNIFE){
|
||||
script.singleFire = EditorGUILayout.Toggle(" Single Fire: ", script.singleFire);
|
||||
script.Recoil = EditorGUILayout.Toggle(" Recoil: ", script.Recoil);
|
||||
}
|
||||
|
||||
if(script.GunType != script.gunType.KNIFE){
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("", "Aim properties", "button");
|
||||
//Aim variables
|
||||
script.Aim.aimPosition = EditorGUILayout.Vector3Field (" Aim Position:", script.Aim.aimPosition);
|
||||
script.Aim.smoothTime = EditorGUILayout.Slider(" Aim Time:", script.Aim.smoothTime, 0, 1);
|
||||
script.Aim.toFov = EditorGUILayout.IntSlider(" Aim Fov:", script.Aim.toFov, 5, 60);
|
||||
script.Aim.aimBobbingAmount = EditorGUILayout.FloatField(" Aim Sway:", script.Aim.aimBobbingAmount );
|
||||
script.Aim.playAnimation = EditorGUILayout.Toggle(" Play Animation:", script.Aim.playAnimation);
|
||||
}
|
||||
|
||||
//Grenade launcher
|
||||
if(script.GunType == script.gunType.GRENADE_LAUNCHER){
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("", "Grenade launcher properties", "button");
|
||||
script.firePoint = EditorGUILayout.ObjectField(" Fire Point:", script.firePoint, Transform, allowSceneObjects) as Transform;
|
||||
script.grenadeLauncher.projectile = EditorGUILayout.ObjectField(" Projectile: ", script.grenadeLauncher.projectile, Rigidbody, allowSceneObjects) as Rigidbody;
|
||||
script.grenadeLauncher.fireSound = EditorGUILayout.ObjectField(" Fire Sound: ", script.grenadeLauncher.fireSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.grenadeLauncher.reloadSound = EditorGUILayout.ObjectField(" Reload Sound: ", script.grenadeLauncher.reloadSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.grenadeLauncher.initialSpeed = EditorGUILayout.IntSlider(" Initial Speed:", script.grenadeLauncher.initialSpeed, 1, 80);
|
||||
script.grenadeLauncher.shotDelay = EditorGUILayout.FloatField(" Shot Delay:", script.grenadeLauncher.shotDelay);
|
||||
script.grenadeLauncher.waitBeforeReload = EditorGUILayout.FloatField(" Wait Before Reload:", script.grenadeLauncher.waitBeforeReload);
|
||||
script.grenadeLauncher.reloadTime = EditorGUILayout.FloatField(" Reload Time:", script.grenadeLauncher.reloadTime);
|
||||
script.grenadeLauncher.ammoCount = EditorGUILayout.IntSlider(" Ammo Count:", script.grenadeLauncher.ammoCount, 0, 999);
|
||||
}
|
||||
|
||||
if(script.GunType == script.gunType.MACHINE_GUN){
|
||||
EditorGUILayout.Space();
|
||||
//Machine gun
|
||||
EditorGUILayout.LabelField("", "Machine gun properties", "button");
|
||||
script.firePoint = EditorGUILayout.ObjectField(" Fire Point:", script.firePoint, Transform, allowSceneObjects) as Transform;
|
||||
script.machineGun.bullet = EditorGUILayout.ObjectField(" Bullet: ", script.machineGun.bullet, Transform, allowSceneObjects) as Transform;
|
||||
script.machineGun.muzzleFlash = EditorGUILayout.ObjectField(" Muzzle Flash:", script.machineGun.muzzleFlash, GameObject, allowSceneObjects) as GameObject;
|
||||
script.machineGun.fireSound = EditorGUILayout.ObjectField(" Fire Sound: ", script.machineGun.fireSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.machineGun.reloadSound = EditorGUILayout.ObjectField(" Reload Sound: ", script.machineGun.reloadSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.machineGun.pointLight = EditorGUILayout.ObjectField(" Muzzle Light:", script.machineGun.pointLight, Light, allowSceneObjects) as Light;
|
||||
script.machineGun.fireRate = EditorGUILayout.FloatField(" Fire Rate: ", script.machineGun.fireRate);
|
||||
script.machineGun.bulletsPerClip = EditorGUILayout.IntSlider( " Bullets Per Clip:", script.machineGun.bulletsPerClip, 0, 999);
|
||||
script.machineGun.clips = EditorGUILayout.IntSlider( " Total Bullets:", script.machineGun.clips, 0, 999);
|
||||
script.machineGun.bulletsLeft = EditorGUILayout.IntSlider( " Current Ammo:", script.machineGun.bulletsLeft, 0, script.machineGun.bulletsPerClip);
|
||||
script.machineGun.reloadTime = EditorGUILayout.FloatField(" Reload Time: ", script.machineGun.reloadTime);
|
||||
script.machineGun.NoAimErrorAngle = EditorGUILayout.IntSlider( " No Aim Error Angle:", script.machineGun.NoAimErrorAngle, 0, 10);
|
||||
script.machineGun.AimErrorAngle = EditorGUILayout.IntSlider( " Aim Error Angle:", script.machineGun.AimErrorAngle, 0, 3);
|
||||
}
|
||||
|
||||
if(script.GunType == script.gunType.SHOTGUN){
|
||||
EditorGUILayout.Space();
|
||||
//Shotgun
|
||||
EditorGUILayout.LabelField("", "Shotgun properties", "button");
|
||||
script.firePoint = EditorGUILayout.ObjectField(" Fire Point:", script.firePoint, Transform, allowSceneObjects) as Transform;
|
||||
script.ShotGun.bullet = EditorGUILayout.ObjectField(" Bullet: ", script.ShotGun.bullet, Transform, allowSceneObjects) as Transform;
|
||||
script.ShotGun.fireSound = EditorGUILayout.ObjectField(" Fire Sound: ", script.ShotGun.fireSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.ShotGun.reloadSound = EditorGUILayout.ObjectField(" Reload Sound: ", script.ShotGun.reloadSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.ShotGun.smoke = EditorGUILayout.ObjectField(" Smoke:", script.ShotGun.smoke, ParticleEmitter, allowSceneObjects) as ParticleEmitter;
|
||||
script.ShotGun.fractions = EditorGUILayout.IntSlider( " Fractions:", script.ShotGun.fractions, 2, 8);
|
||||
script.ShotGun.errorAngle = EditorGUILayout.IntSlider( " Error Angle:", script.ShotGun.errorAngle, 2, 10);
|
||||
script.ShotGun.fireRate = EditorGUILayout.FloatField(" Fire Rate: ", script.ShotGun.fireRate);
|
||||
script.ShotGun.reloadTime = EditorGUILayout.FloatField(" Reload Time: ", script.ShotGun.reloadTime);
|
||||
script.ShotGun.bulletsPerClip = EditorGUILayout.IntSlider( " Bullets Per Clip:", script.ShotGun.bulletsPerClip, 0, 20);
|
||||
script.ShotGun.bulletsLeft = EditorGUILayout.IntSlider( " Current Ammo:", script.ShotGun.bulletsLeft, 0, script.ShotGun.bulletsPerClip);
|
||||
script.ShotGun.clips = EditorGUILayout.IntSlider( " Total Bullets:", script.ShotGun.clips, 0, 999);
|
||||
}
|
||||
|
||||
if(script.GunType == script.gunType.KNIFE){
|
||||
EditorGUILayout.Space();
|
||||
//Knife
|
||||
EditorGUILayout.LabelField("", "Knife properties", "button");
|
||||
script.knife.bullet = EditorGUILayout.ObjectField(" Bullet: ", script.knife.bullet, Transform, allowSceneObjects) as Transform;
|
||||
script.knife.fireSound = EditorGUILayout.ObjectField(" Fire Sound: ", script.knife.fireSound, AudioClip, allowSceneObjects) as AudioClip;
|
||||
script.knife.fireRate = EditorGUILayout.FloatField(" Fire Rate: ", script.knife.fireRate);
|
||||
script.knife.delayTime = EditorGUILayout.FloatField(" Delay Time: ", script.knife.delayTime);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("", "Rotation realism", "button");
|
||||
script.RotRealism.RotationAmplitude = EditorGUILayout.IntSlider( " Rotation Amplitude:", script.RotRealism.RotationAmplitude, 0, 8);
|
||||
script.RotRealism.smooth = EditorGUILayout.IntSlider( " Smooth:", script.RotRealism.smooth, 0, 10);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("", "Smooth move", "button");
|
||||
script.SmoothMovement.Smooth = EditorGUILayout.IntSlider( " Smooth:", script.SmoothMovement.Smooth, 0, 10);
|
||||
script.SmoothMovement.maxAmount = EditorGUILayout.Slider(" Move Responce: ", script.SmoothMovement.maxAmount, 0, 1);
|
||||
|
||||
if(script.Recoil == true){
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("", "Main camera recoil effect", "button");
|
||||
script.CameraRecoil.recoilPower = EditorGUILayout.FloatField(" Recoil Power: ", script.CameraRecoil.recoilPower);
|
||||
script.CameraRecoil.shakeAmount = EditorGUILayout.FloatField(" Shake Amount: ", script.CameraRecoil.shakeAmount);
|
||||
script.CameraRecoil.smooth = EditorGUILayout.IntSlider( " Smooth:", script.CameraRecoil.smooth, 0, 20);
|
||||
}
|
||||
if (GUI.changed){
|
||||
EditorUtility.SetDirty (script);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bcfdd7b5fb22e24ebc5b50535877740
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96ca89d0115f6ee4684e46ca34bf65bf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,275 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//Use this script to controll thrird person animation
|
||||
|
||||
#pragma strict
|
||||
|
||||
import System.Collections.Generic;
|
||||
|
||||
//@script ExecuteInEditMode
|
||||
//Use this gameObject to send messages to AnimationSync.cs
|
||||
var animationSyncHelper : GameObject;
|
||||
var animationForHands : GameObject;
|
||||
//This gameObject.name will tell AnimationSync.cs which third person weapon is active now
|
||||
var activeWeapon : GameObject;
|
||||
enum Action{Stand, Crouch, Prone}
|
||||
var action : Action;
|
||||
|
||||
class animations{
|
||||
//Edit pose
|
||||
//var poseAnimation : AnimationClip;
|
||||
//Idle animations
|
||||
var jumpPose : AnimationClip;
|
||||
var stayIdle : AnimationClip;
|
||||
var crouchIdle : AnimationClip;
|
||||
var proneIdle : AnimationClip;
|
||||
//Walk Animations
|
||||
var walkFront : AnimationClip;
|
||||
var walkBack : AnimationClip;
|
||||
var walkLeft : AnimationClip;
|
||||
var walkRight : AnimationClip;
|
||||
var walkAnimationsSpeed : float = 1;
|
||||
//Run animations
|
||||
var runFront : AnimationClip;
|
||||
var runAnimationsSpeed : float = 1;
|
||||
//Crouch animations
|
||||
var crouchFront : AnimationClip;
|
||||
var crouchLeft : AnimationClip;
|
||||
var crouchRight : AnimationClip;
|
||||
var crouchBack : AnimationClip;
|
||||
var crouchAnimationsSpeed : float = 1;
|
||||
//Prone Animations
|
||||
var proneFront : AnimationClip;
|
||||
var proneLeft : AnimationClip;
|
||||
var proneRight : AnimationClip;
|
||||
var proneBack : AnimationClip;
|
||||
var proneAnimationsSpeed : float = 1;
|
||||
//Weapon animations
|
||||
var pistolIdle : AnimationClip;
|
||||
var knifeIdle : AnimationClip;
|
||||
var gunIdle : AnimationClip;
|
||||
/*var fire : AnimationClip;
|
||||
var reload : AnimationClip;*/
|
||||
}
|
||||
|
||||
var Animations : animations;
|
||||
|
||||
var twoHandedWeapons : List.<WeaponScript>;
|
||||
var pistols : List.<WeaponScript>;
|
||||
var knivesNades : List.<WeaponScript>;
|
||||
|
||||
private var fpsController : FPScontroller;
|
||||
private var weapManager : WeaponManager;
|
||||
|
||||
function Start () {
|
||||
fpsController = GameObject.FindWithTag("Player").GetComponent.<FPScontroller>();
|
||||
configureAnimations();
|
||||
weapManager = GameObject.FindWithTag("WeaponManager").GetComponent.<WeaponManager>();
|
||||
//Play pose in the Editor
|
||||
/*if(poseAnimation){
|
||||
var state : AnimationState = animation[pistolIdle.name];
|
||||
state.enabled = true;
|
||||
state.weight = 1;
|
||||
state.normalizedTime = 0;
|
||||
|
||||
animation.Sample();
|
||||
}*/
|
||||
if(weapManager){
|
||||
ThirdPersonWeaponControl();
|
||||
}
|
||||
}
|
||||
|
||||
function Update () {
|
||||
activeWeapon.name = weapManager.SelectedWeapon.weaponName;
|
||||
if(!fpsController.crouch && !fpsController.prone){
|
||||
action = Action.Stand;
|
||||
}
|
||||
else if(fpsController.crouch && !fpsController.prone){
|
||||
action = Action.Crouch;
|
||||
}
|
||||
else if(!fpsController.crouch && fpsController.prone){
|
||||
action = Action.Prone;
|
||||
}
|
||||
|
||||
if(action == Action.Stand){
|
||||
if(fpsController.grounded){
|
||||
if(fpsController.Walking && !fpsController.Running){
|
||||
if( Input.GetKey(KeyCode.W)){
|
||||
animation.CrossFade(Animations.walkFront.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.walkFront.name;
|
||||
}
|
||||
else if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.walkLeft.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.walkLeft.name;
|
||||
}
|
||||
else if( Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.walkRight.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.walkRight.name;
|
||||
}
|
||||
else if(Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.walkBack.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.walkBack.name;
|
||||
}
|
||||
}
|
||||
else if(fpsController.Walking && fpsController.Running){
|
||||
if( Input.GetKey(KeyCode.W) ){
|
||||
animation.CrossFade(Animations.runFront.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.runFront.name;
|
||||
}
|
||||
}
|
||||
if(!fpsController.Walking){
|
||||
animation.CrossFade(Animations.stayIdle.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.stayIdle.name;
|
||||
}
|
||||
}else{
|
||||
animation.CrossFade(Animations.jumpPose.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.jumpPose.name;
|
||||
}
|
||||
}
|
||||
if(action == Action.Crouch){
|
||||
if(fpsController.Walking ){
|
||||
if( Input.GetKey(KeyCode.W) ){
|
||||
animation.CrossFade(Animations.crouchFront.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.crouchFront.name;
|
||||
}
|
||||
else if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.crouchLeft.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.crouchLeft.name;
|
||||
}
|
||||
else if( Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.crouchRight.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.crouchRight.name;
|
||||
}
|
||||
else if(Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.crouchBack.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.crouchBack.name;
|
||||
}
|
||||
}else{
|
||||
animation.CrossFade(Animations.crouchIdle.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.crouchIdle.name;
|
||||
}
|
||||
}
|
||||
if(action == Action.Prone){
|
||||
if(fpsController.Walking ){
|
||||
if( Input.GetKey(KeyCode.W) ){
|
||||
animation.CrossFade(Animations.proneFront.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.proneFront.name;
|
||||
}
|
||||
else if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.proneLeft.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.proneLeft.name;
|
||||
}
|
||||
else if( Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.proneRight.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.proneRight.name;
|
||||
}
|
||||
else if(Input.GetKey(KeyCode.S)){
|
||||
animation.CrossFade(Animations.proneBack.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.proneBack.name;
|
||||
}
|
||||
}else{
|
||||
animation.CrossFade(Animations.proneIdle.name, 0.2);
|
||||
//Send animation name (needed for multiplayer)
|
||||
animationSyncHelper.name = Animations.proneIdle.name;
|
||||
}
|
||||
}
|
||||
ThirdPersonWeaponControl();
|
||||
}
|
||||
|
||||
function ThirdPersonWeaponControl(){
|
||||
if(action != Action.Prone){
|
||||
if(twoHandedWeapons.Contains(weapManager.SelectedWeapon)){
|
||||
animationForHands.name = Animations.gunIdle.name;
|
||||
}
|
||||
else if(pistols.Contains(weapManager.SelectedWeapon)){
|
||||
animationForHands.name = Animations.pistolIdle.name;
|
||||
}
|
||||
else if(knivesNades.Contains(weapManager.SelectedWeapon)){
|
||||
animationForHands.name = Animations.knifeIdle.name;
|
||||
}
|
||||
}else{
|
||||
animationForHands.name = "Null";
|
||||
}
|
||||
}
|
||||
|
||||
function configureAnimations(){
|
||||
//Set animations Wrap Mode and Speed
|
||||
if(Animations.stayIdle){
|
||||
animation[Animations.stayIdle.name].wrapMode = WrapMode.Loop;
|
||||
}
|
||||
if(Animations.crouchIdle){
|
||||
animation[Animations.crouchIdle.name].wrapMode = WrapMode.Loop;
|
||||
}
|
||||
if(Animations.proneIdle){
|
||||
animation[Animations.proneIdle.name].wrapMode = WrapMode.Loop;
|
||||
}
|
||||
if(Animations.walkFront){
|
||||
animation[Animations.walkFront.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.walkFront.name].speed = Animations.walkAnimationsSpeed;
|
||||
}
|
||||
if(Animations.walkBack){
|
||||
animation[Animations.walkBack.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.walkBack.name].speed = Animations.walkAnimationsSpeed;
|
||||
}
|
||||
if(Animations.walkLeft){
|
||||
animation[Animations.walkLeft.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.walkLeft.name].speed = Animations.walkAnimationsSpeed;
|
||||
}
|
||||
if(Animations.walkRight){
|
||||
animation[Animations.walkRight.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.walkRight.name].speed = Animations.walkAnimationsSpeed;
|
||||
}
|
||||
if(Animations.runFront){
|
||||
animation[Animations.runFront.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.runFront.name].speed = Animations.runAnimationsSpeed;
|
||||
}
|
||||
if(Animations.crouchFront){
|
||||
animation[Animations.crouchFront.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.crouchFront.name].speed = Animations.crouchAnimationsSpeed;
|
||||
}
|
||||
if(Animations.crouchLeft){
|
||||
animation[Animations.crouchLeft.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.crouchLeft.name].speed = Animations.crouchAnimationsSpeed;
|
||||
}
|
||||
if(Animations.crouchRight){
|
||||
animation[Animations.crouchRight.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.crouchRight.name].speed = Animations.crouchAnimationsSpeed;
|
||||
}
|
||||
if(Animations.crouchBack){
|
||||
animation[Animations.crouchBack.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.crouchBack.name].speed = Animations.crouchAnimationsSpeed;
|
||||
}
|
||||
if(Animations.proneFront){
|
||||
animation[Animations.proneFront.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.proneFront.name].speed = Animations.proneAnimationsSpeed;
|
||||
}
|
||||
if(Animations.proneLeft){
|
||||
animation[Animations.proneLeft.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.proneLeft.name].speed = Animations.proneAnimationsSpeed;
|
||||
}
|
||||
if(Animations.proneRight){
|
||||
animation[Animations.proneRight.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.proneRight.name].speed = Animations.proneAnimationsSpeed;
|
||||
}
|
||||
if(Animations.proneBack){
|
||||
animation[Animations.proneBack.name].wrapMode = WrapMode.Loop;
|
||||
animation[Animations.proneBack.name].speed = Animations.proneAnimationsSpeed;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5526dce69425e31429436adb8dfd845a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,73 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
enum RotationAxes{ MouseXAndY, MouseX, MouseY }
|
||||
var axes = RotationAxes.MouseXAndY;
|
||||
var sensitivity : float = 4;
|
||||
var aimSensitivity : float = 2;
|
||||
|
||||
@HideInInspector
|
||||
var sensitivityX : float = 15;
|
||||
@HideInInspector
|
||||
var sensitivityY : float = 15;
|
||||
private var minimumX : float = -360;
|
||||
private var maximumX : float = 360;
|
||||
|
||||
var minimumY : float = -80;
|
||||
var maximumY : float = 80;
|
||||
|
||||
private var rotationY : float = 0;
|
||||
|
||||
//Find WeaponManager script to know when selected weapon is aimed or not
|
||||
private var weapManager : WeaponManager;
|
||||
private var weapScript : WeaponScript;
|
||||
|
||||
//Added for sniper scope
|
||||
@HideInInspector
|
||||
public var currentSensitivity : float;
|
||||
|
||||
function Awake (){
|
||||
weapManager = gameObject.FindWithTag("WeaponManager").GetComponent.<WeaponManager>();
|
||||
}
|
||||
|
||||
function Update (){
|
||||
if(Time.timeScale < 0.01)
|
||||
return;
|
||||
if (axes == RotationAxes.MouseXAndY){
|
||||
var rotationX : float = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
|
||||
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
|
||||
}
|
||||
else if (axes == RotationAxes.MouseX){
|
||||
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
|
||||
}else{
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
|
||||
}
|
||||
|
||||
//Find current selected weapon script
|
||||
if(weapManager.SelectedWeapon){
|
||||
weapScript = weapManager.SelectedWeapon.GetComponent.<WeaponScript>();
|
||||
}
|
||||
//Check if weapon aimed or not
|
||||
if(weapScript && weapScript.aimed){
|
||||
currentSensitivity = aimSensitivity;
|
||||
}else{
|
||||
currentSensitivity = sensitivity;
|
||||
}
|
||||
sensitivityX = currentSensitivity;
|
||||
sensitivityY = currentSensitivity;
|
||||
}
|
||||
|
||||
function Recoil(amount : float){
|
||||
rotationY += amount;
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Character/FPS MouseLook")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41b2ea76a35b6704ea7f06874525987b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,49 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
var walkSounds : AudioClip[];
|
||||
var walkStepLength = 0.45;
|
||||
var runStepLenght = 0.38;
|
||||
var crouchStepLenght = 0.38;
|
||||
|
||||
private var controller : CharacterController;
|
||||
private var motor : FPScontroller;
|
||||
private var lastStep= -10.0;
|
||||
private var StepLenght : float;
|
||||
|
||||
function Awake(){
|
||||
StepLenght = walkStepLength;
|
||||
controller = GetComponent(CharacterController);
|
||||
motor = GetComponent(FPScontroller);
|
||||
}
|
||||
|
||||
function FixedUpdate(){
|
||||
//Check when player walk or run to play footstep sounds with different speed
|
||||
if(motor.prone)
|
||||
return;
|
||||
if(motor.Walking && motor.grounded && !motor.crouch){
|
||||
PlayStepSounds();
|
||||
StepLenght = walkStepLength;
|
||||
}
|
||||
if(motor.Running && motor.grounded){
|
||||
PlayStepSounds();
|
||||
StepLenght = runStepLenght;
|
||||
}
|
||||
if(motor.Walking && motor.crouch && motor.grounded){
|
||||
PlayStepSounds();
|
||||
StepLenght = crouchStepLenght;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function PlayStepSounds(){
|
||||
if (Time.time > StepLenght + lastStep){
|
||||
audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
|
||||
audio.Play();
|
||||
lastStep = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
@script RequireComponent (AudioSource)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbba277a44c379e458937319f97a6378
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,884 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
#pragma implicit
|
||||
#pragma downcast
|
||||
|
||||
// Does this script currently respond to input?
|
||||
var canControl : boolean = true;
|
||||
|
||||
var useFixedUpdate : boolean = true;
|
||||
|
||||
//Check when run, walk or when can run or not
|
||||
@HideInInspector
|
||||
public var Running : boolean;
|
||||
@HideInInspector
|
||||
public var Walking : boolean;
|
||||
@HideInInspector
|
||||
public var canRun : boolean;
|
||||
|
||||
//Ladder variables
|
||||
private var mainCamera : GameObject = null;
|
||||
@HideInInspector
|
||||
public var onLadder = false;
|
||||
private var ladderHopSpeed = 6.0;
|
||||
|
||||
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
|
||||
// Very handy for organization!
|
||||
|
||||
// The current global direction we want the character to move in.
|
||||
@System.NonSerialized
|
||||
var inputMoveDirection : Vector3 = Vector3.zero;
|
||||
|
||||
// Is the jump button held down? We use this interface instead of checking
|
||||
// for the jump button directly so this script can also be used by AIs.
|
||||
@System.NonSerialized
|
||||
var inputJump : boolean = false;
|
||||
|
||||
@HideInInspector
|
||||
var inputRun : boolean = false;
|
||||
|
||||
@HideInInspector
|
||||
var inputCrouch : boolean = false;
|
||||
|
||||
@HideInInspector
|
||||
var inputProne : boolean = false;
|
||||
|
||||
class FPScontrollerMovement {
|
||||
// The maximum horizontal speed when moving
|
||||
@HideInInspector
|
||||
var maxForwardSpeed : float = 10.0;
|
||||
@HideInInspector
|
||||
var maxSidewaysSpeed : float = 10.0;
|
||||
@HideInInspector
|
||||
var maxBackwardsSpeed : float = 10.0;
|
||||
|
||||
//Run and walk variables
|
||||
var WalkSpeed : float = 6.0;
|
||||
var RunSpeed : float = 9.0;
|
||||
//Crouch
|
||||
var canCrouch : boolean = true;
|
||||
var CrouchSpeed : float = 3.0;
|
||||
var crouchHeight : float = 1.5;
|
||||
var crouchSmooth : float = 8;
|
||||
//prone
|
||||
var canProne : boolean = true;
|
||||
var ProneSpeed : float = 1.5;
|
||||
var proneHeight : float = 0.7;
|
||||
|
||||
// Curve for multiplying speed based on slope (negative = downwards)
|
||||
var slopeSpeedMultiplier : AnimationCurve = AnimationCurve(Keyframe(-90, 1), Keyframe(0, 1), Keyframe(90, 0));
|
||||
|
||||
// How fast does the character change speeds? Higher is faster.
|
||||
var maxGroundAcceleration : float = 30.0;
|
||||
var maxAirAcceleration : float = 20.0;
|
||||
|
||||
// The gravity for the character
|
||||
var gravity : float = 10.0;
|
||||
var maxFallSpeed : float = 20.0;
|
||||
|
||||
@HideInInspector
|
||||
var enableGravity : boolean = true;
|
||||
|
||||
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
|
||||
// Very handy for organization!
|
||||
|
||||
// The last collision flags returned from controller.Move
|
||||
@System.NonSerialized
|
||||
var collisionFlags : CollisionFlags;
|
||||
|
||||
// We will keep track of the character's current velocity,
|
||||
@System.NonSerialized
|
||||
var velocity : Vector3;
|
||||
|
||||
// This keeps track of our current velocity while we're not grounded
|
||||
@System.NonSerialized
|
||||
var frameVelocity : Vector3 = Vector3.zero;
|
||||
|
||||
@System.NonSerialized
|
||||
var hitPoint : Vector3 = Vector3.zero;
|
||||
|
||||
@System.NonSerialized
|
||||
var lastHitPoint : Vector3 = Vector3(Mathf.Infinity, 0, 0);
|
||||
}
|
||||
|
||||
var movement : FPScontrollerMovement = FPScontrollerMovement();
|
||||
|
||||
//Crouching vars
|
||||
@HideInInspector
|
||||
public var crouch : boolean;
|
||||
private var standartHeight : float;
|
||||
private var lookObj : GameObject;
|
||||
private var centerY : float;
|
||||
private var canStand : boolean;
|
||||
private var canStandCrouch : boolean = true;
|
||||
|
||||
//Prone vars
|
||||
@HideInInspector
|
||||
public var prone : boolean;
|
||||
|
||||
enum FPSMovementTransferOnJump {
|
||||
None, // The jump is not affected by velocity of floor at all.
|
||||
InitTransfer, // Jump gets its initial velocity from the floor, then gradualy comes to a stop.
|
||||
PermaTransfer, // Jump gets its initial velocity from the floor, and keeps that velocity until landing.
|
||||
PermaLocked // Jump is relative to the movement of the last touched floor and will move together with that floor.
|
||||
}
|
||||
|
||||
// We will contain all the jumping related variables in one helper class for clarity.
|
||||
class FPScontrollerJumping {
|
||||
// Can the character jump?
|
||||
var enabled : boolean = true;
|
||||
|
||||
// How high do we jump when pressing jump and letting go immediately
|
||||
var baseHeight : float = 1.0;
|
||||
|
||||
// We add extraHeight units (meters) on top when holding the button down longer while jumping
|
||||
var extraHeight : float = 4.1;
|
||||
|
||||
// How much does the character jump out perpendicular to the surface on walkable surfaces?
|
||||
// 0 means a fully vertical jump and 1 means fully perpendicular.
|
||||
var perpAmount : float = 0.0;
|
||||
|
||||
// How much does the character jump out perpendicular to the surface on too steep surfaces?
|
||||
// 0 means a fully vertical jump and 1 means fully perpendicular.
|
||||
var steepPerpAmount : float = 0.5;
|
||||
|
||||
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
|
||||
// Very handy for organization!
|
||||
|
||||
// Are we jumping? (Initiated with jump button and not grounded yet)
|
||||
// To see if we are just in the air (initiated by jumping OR falling) see the grounded variable.
|
||||
@System.NonSerialized
|
||||
var jumping : boolean = false;
|
||||
|
||||
@System.NonSerialized
|
||||
var holdingJumpButton : boolean = false;
|
||||
|
||||
// the time we jumped at (Used to determine for how long to apply extra jump power after jumping.)
|
||||
@System.NonSerialized
|
||||
var lastStartTime : float = 0.0;
|
||||
|
||||
@System.NonSerialized
|
||||
var lastButtonDownTime : float = -100;
|
||||
|
||||
@System.NonSerialized
|
||||
var jumpDir : Vector3 = Vector3.up;
|
||||
}
|
||||
|
||||
var jumping : FPScontrollerJumping = FPScontrollerJumping();
|
||||
|
||||
class FPScontrollerMovingPlatform {
|
||||
var enabled : boolean = true;
|
||||
|
||||
var movementTransfer : FPSMovementTransferOnJump = FPSMovementTransferOnJump.PermaTransfer;
|
||||
|
||||
@System.NonSerialized
|
||||
var hitPlatform : Transform;
|
||||
|
||||
@System.NonSerialized
|
||||
var activePlatform : Transform;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeLocalPoint : Vector3;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeGlobalPoint : Vector3;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeLocalRotation : Quaternion;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeGlobalRotation : Quaternion;
|
||||
|
||||
@System.NonSerialized
|
||||
var lastMatrix : Matrix4x4;
|
||||
|
||||
@System.NonSerialized
|
||||
var platformVelocity : Vector3;
|
||||
|
||||
@System.NonSerialized
|
||||
var newPlatform : boolean;
|
||||
}
|
||||
|
||||
var movingPlatform : FPScontrollerMovingPlatform = FPScontrollerMovingPlatform();
|
||||
|
||||
class FPScontrollerSliding {
|
||||
// Does the character slide on too steep surfaces?
|
||||
var enabled : boolean = true;
|
||||
|
||||
// How fast does the character slide on steep surfaces?
|
||||
var slidingSpeed : float = 15;
|
||||
|
||||
// How much can the player control the sliding direction?
|
||||
// If the value is 0.5 the player can slide sideways with half the speed of the downwards sliding speed.
|
||||
var sidewaysControl : float = 1.0;
|
||||
|
||||
// How much can the player influence the sliding speed?
|
||||
// If the value is 0.5 the player can speed the sliding up to 150% or slow it down to 50%.
|
||||
var speedControl : float = 0.4;
|
||||
}
|
||||
|
||||
var sliding : FPScontrollerSliding = FPScontrollerSliding();
|
||||
|
||||
class FPScontrollerPushing {
|
||||
//Push RigidBodies
|
||||
var canPush : boolean = true;
|
||||
var pushPower = 2.0;
|
||||
}
|
||||
var pushing : FPScontrollerPushing;
|
||||
|
||||
@System.NonSerialized
|
||||
var grounded : boolean = true;
|
||||
|
||||
@System.NonSerialized
|
||||
var groundNormal : Vector3 = Vector3.zero;
|
||||
|
||||
private var lastGroundNormal : Vector3 = Vector3.zero;
|
||||
|
||||
private var tr : Transform;
|
||||
|
||||
private var controller : CharacterController;
|
||||
|
||||
function Awake () {
|
||||
controller = GetComponent (CharacterController);
|
||||
standartHeight = controller.height;
|
||||
lookObj = GameObject.FindWithTag("LookObject");
|
||||
centerY = controller.center.y;
|
||||
tr = transform;
|
||||
mainCamera = GameObject.FindWithTag("MainCamera");
|
||||
canRun = true;
|
||||
canStand = true;
|
||||
setupBools();
|
||||
}
|
||||
|
||||
function setupBools(){
|
||||
if(!movement.canProne){
|
||||
movement.canProne = true;
|
||||
yield WaitForSeconds(0.2);
|
||||
movement.canProne = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function UpdateFunction () {
|
||||
// We copy the actual velocity into a temporary variable that we can manipulate.
|
||||
var velocity : Vector3 = movement.velocity;
|
||||
|
||||
// Update velocity based on input
|
||||
velocity = ApplyInputVelocityChange(velocity);
|
||||
|
||||
// Apply gravity and jumping force
|
||||
if(movement.enableGravity){
|
||||
if((prone || crouch) && inputJump)
|
||||
return;
|
||||
velocity = ApplyGravityAndJumping (velocity);
|
||||
}
|
||||
// Moving platform support
|
||||
var moveDistance : Vector3 = Vector3.zero;
|
||||
if (MoveWithPlatform()) {
|
||||
var newGlobalPoint : Vector3 = movingPlatform.activePlatform.TransformPoint(movingPlatform.activeLocalPoint);
|
||||
moveDistance = (newGlobalPoint - movingPlatform.activeGlobalPoint);
|
||||
if (moveDistance != Vector3.zero)
|
||||
controller.Move(moveDistance);
|
||||
|
||||
// Support moving platform rotation as well:
|
||||
var newGlobalRotation : Quaternion = movingPlatform.activePlatform.rotation * movingPlatform.activeLocalRotation;
|
||||
var rotationDiff : Quaternion = newGlobalRotation * Quaternion.Inverse(movingPlatform.activeGlobalRotation);
|
||||
|
||||
var yRotation = rotationDiff.eulerAngles.y;
|
||||
if (yRotation != 0) {
|
||||
// Prevent rotation of the local up vector
|
||||
tr.Rotate(0, yRotation, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Save lastPosition for velocity calculation.
|
||||
var lastPosition : Vector3 = tr.position;
|
||||
|
||||
// We always want the movement to be framerate independent. Multiplying by Time.deltaTime does this.
|
||||
var currentMovementOffset : Vector3 = velocity * Time.deltaTime;
|
||||
|
||||
// Find out how much we need to push towards the ground to avoid loosing grouning
|
||||
// when walking down a step or over a sharp change in slope.
|
||||
var pushDownOffset : float = Mathf.Max(controller.stepOffset, Vector3(currentMovementOffset.x, 0, currentMovementOffset.z).magnitude);
|
||||
if (grounded)
|
||||
currentMovementOffset -= pushDownOffset * Vector3.up;
|
||||
|
||||
// Reset variables that will be set by collision function
|
||||
movingPlatform.hitPlatform = null;
|
||||
groundNormal = Vector3.zero;
|
||||
|
||||
// Move our character!
|
||||
movement.collisionFlags = controller.Move (currentMovementOffset);
|
||||
|
||||
movement.lastHitPoint = movement.hitPoint;
|
||||
lastGroundNormal = groundNormal;
|
||||
|
||||
if (movingPlatform.enabled && movingPlatform.activePlatform != movingPlatform.hitPlatform) {
|
||||
if (movingPlatform.hitPlatform != null) {
|
||||
movingPlatform.activePlatform = movingPlatform.hitPlatform;
|
||||
movingPlatform.lastMatrix = movingPlatform.hitPlatform.localToWorldMatrix;
|
||||
movingPlatform.newPlatform = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the velocity based on the current and previous position.
|
||||
// This means our velocity will only be the amount the character actually moved as a result of collisions.
|
||||
var oldHVelocity : Vector3 = new Vector3(velocity.x, 0, velocity.z);
|
||||
movement.velocity = (tr.position - lastPosition) / Time.deltaTime;
|
||||
var newHVelocity : Vector3 = new Vector3(movement.velocity.x, 0, movement.velocity.z);
|
||||
|
||||
// The CharacterController can be moved in unwanted directions when colliding with things.
|
||||
// We want to prevent this from influencing the recorded velocity.
|
||||
if (oldHVelocity == Vector3.zero) {
|
||||
movement.velocity = new Vector3(0, movement.velocity.y, 0);
|
||||
}
|
||||
else {
|
||||
var projectedNewVelocity : float = Vector3.Dot(newHVelocity, oldHVelocity) / oldHVelocity.sqrMagnitude;
|
||||
movement.velocity = oldHVelocity * Mathf.Clamp01(projectedNewVelocity) + movement.velocity.y * Vector3.up;
|
||||
}
|
||||
|
||||
if (movement.velocity.y < velocity.y - 0.001) {
|
||||
if (movement.velocity.y < 0) {
|
||||
// Something is forcing the CharacterController down faster than it should.
|
||||
// Ignore this
|
||||
movement.velocity.y = velocity.y;
|
||||
}
|
||||
else {
|
||||
// The upwards movement of the CharacterController has been blocked.
|
||||
// This is treated like a ceiling collision - stop further jumping here.
|
||||
jumping.holdingJumpButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
// We were grounded but just loosed grounding
|
||||
if (grounded && !IsGroundedTest()) {
|
||||
grounded = false;
|
||||
|
||||
// Apply inertia from platform
|
||||
if (movingPlatform.enabled &&
|
||||
(movingPlatform.movementTransfer == FPSMovementTransferOnJump.InitTransfer ||
|
||||
movingPlatform.movementTransfer == FPSMovementTransferOnJump.PermaTransfer)
|
||||
) {
|
||||
movement.frameVelocity = movingPlatform.platformVelocity;
|
||||
movement.velocity += movingPlatform.platformVelocity;
|
||||
}
|
||||
|
||||
SendMessage("OnFall", SendMessageOptions.DontRequireReceiver);
|
||||
// We pushed the character down to ensure it would stay on the ground if there was any.
|
||||
// But there wasn't so now we cancel the downwards offset to make the fall smoother.
|
||||
tr.position += pushDownOffset * Vector3.up;
|
||||
}
|
||||
// We were not grounded but just landed on something
|
||||
else if (!grounded && IsGroundedTest()) {
|
||||
grounded = true;
|
||||
jumping.jumping = false;
|
||||
SubtractNewPlatformVelocity();
|
||||
|
||||
SendMessage("OnLand", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
// Moving platforms support
|
||||
if (MoveWithPlatform()) {
|
||||
// Use the center of the lower half sphere of the capsule as reference point.
|
||||
// This works best when the character is standing on moving tilting platforms.
|
||||
movingPlatform.activeGlobalPoint = tr.position + Vector3.up * (controller.center.y - controller.height*0.5 + controller.radius);
|
||||
movingPlatform.activeLocalPoint = movingPlatform.activePlatform.InverseTransformPoint(movingPlatform.activeGlobalPoint);
|
||||
|
||||
// Support moving platform rotation as well:
|
||||
movingPlatform.activeGlobalRotation = tr.rotation;
|
||||
movingPlatform.activeLocalRotation = Quaternion.Inverse(movingPlatform.activePlatform.rotation) * movingPlatform.activeGlobalRotation;
|
||||
}
|
||||
}
|
||||
|
||||
function FixedUpdate () {
|
||||
if (movingPlatform.enabled) {
|
||||
if (movingPlatform.activePlatform != null) {
|
||||
if (!movingPlatform.newPlatform) {
|
||||
var lastVelocity : Vector3 = movingPlatform.platformVelocity;
|
||||
|
||||
movingPlatform.platformVelocity = (
|
||||
movingPlatform.activePlatform.localToWorldMatrix.MultiplyPoint3x4(movingPlatform.activeLocalPoint)
|
||||
- movingPlatform.lastMatrix.MultiplyPoint3x4(movingPlatform.activeLocalPoint)
|
||||
) / Time.deltaTime;
|
||||
}
|
||||
movingPlatform.lastMatrix = movingPlatform.activePlatform.localToWorldMatrix;
|
||||
movingPlatform.newPlatform = false;
|
||||
}
|
||||
else {
|
||||
movingPlatform.platformVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
if (useFixedUpdate){
|
||||
UpdateFunction();
|
||||
}
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if (!useFixedUpdate){
|
||||
UpdateFunction();
|
||||
}
|
||||
|
||||
//Run input
|
||||
if(Input.GetAxis("Vertical") > 0.1 && inputRun && canRun && !onLadder && Walking){
|
||||
if(canStand && canStandCrouch){
|
||||
OnRunning();
|
||||
}
|
||||
}else{
|
||||
OffRunning();
|
||||
}
|
||||
|
||||
//Check when walk or not
|
||||
if ((movement.velocity.x || movement.velocity.z) > 0.01 || (movement.velocity.x || movement.velocity.z) < -0.01) {
|
||||
Walking = true;
|
||||
}else{
|
||||
Walking = false;
|
||||
}
|
||||
|
||||
if(!canControl)
|
||||
return;
|
||||
|
||||
if(movement.canCrouch){
|
||||
if(!onLadder){
|
||||
Crouch();
|
||||
}
|
||||
}
|
||||
|
||||
if(movement.canProne){
|
||||
if(!onLadder){
|
||||
Prone();
|
||||
}
|
||||
}
|
||||
|
||||
if(onLadder){
|
||||
grounded = false;
|
||||
crouch = false;
|
||||
prone = false;
|
||||
}
|
||||
|
||||
if(!crouch && !prone && controller.height < standartHeight-0.01){
|
||||
controller.height = Mathf.Lerp(controller.height, standartHeight, Time.deltaTime/movement.crouchSmooth);
|
||||
controller.center.y = Mathf.Lerp(controller.center.y, centerY, Time.deltaTime/movement.crouchSmooth);
|
||||
lookObj.transform.localPosition.y = Mathf.Lerp(lookObj.transform.localPosition.y, standartHeight, Time.deltaTime/movement.crouchSmooth);
|
||||
}
|
||||
}
|
||||
|
||||
function Prone(){
|
||||
var up = transform.TransformDirection(Vector3.up);
|
||||
var hit : RaycastHit;
|
||||
var charCtrl : CharacterController = GetComponent(CharacterController);
|
||||
var p1 : Vector3 = transform.position;
|
||||
//Input control
|
||||
if(inputProne && !Running && !onLadder && (canStand || crouch)){
|
||||
crouch = false;
|
||||
prone = !prone;
|
||||
if(!prone){
|
||||
crouch = true;
|
||||
}else{
|
||||
canStandCrouch = true;
|
||||
}
|
||||
if(canStandCrouch){
|
||||
crouch = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(inputJump && prone){
|
||||
if(canStand){
|
||||
prone = false;
|
||||
crouch = true;
|
||||
if(canStandCrouch){
|
||||
crouch = false;
|
||||
}else{
|
||||
crouch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(prone || Running){
|
||||
if (!Physics.SphereCast (p1, charCtrl.radius, transform.up, hit, movement.crouchHeight*0.9)) {
|
||||
if(Running && prone){
|
||||
prone = false;
|
||||
if(!prone){
|
||||
crouch = true;
|
||||
}
|
||||
if(canStandCrouch){
|
||||
crouch = false;
|
||||
}
|
||||
}
|
||||
if(prone){
|
||||
canStand = true;
|
||||
}
|
||||
}else{
|
||||
if(prone){
|
||||
canStand = false;
|
||||
}
|
||||
//print("We hit something");
|
||||
}
|
||||
}
|
||||
|
||||
if(prone && !crouch){
|
||||
if(controller.height > movement.proneHeight+0.01){
|
||||
controller.height = Mathf.Lerp(controller.height, movement.proneHeight, Time.deltaTime/movement.crouchSmooth);
|
||||
controller.center.y = Mathf.Lerp(controller.center.y, movement.proneHeight/2, Time.deltaTime/movement.crouchSmooth);
|
||||
lookObj.transform.localPosition.y = Mathf.Lerp(lookObj.transform.localPosition.y, movement.proneHeight, Time.deltaTime/movement.crouchSmooth);
|
||||
movement.maxForwardSpeed = movement.ProneSpeed;
|
||||
movement.maxSidewaysSpeed = movement.ProneSpeed;
|
||||
movement.maxBackwardsSpeed = movement.ProneSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Crouch(){
|
||||
var up = transform.TransformDirection(Vector3.up);
|
||||
var hit : RaycastHit;
|
||||
var charCtrl : CharacterController = GetComponent(CharacterController);
|
||||
var p1 : Vector3 = transform.position;
|
||||
//Input control
|
||||
if(inputCrouch && ! Running && !onLadder && canStand){
|
||||
prone = false;
|
||||
crouch = !crouch;
|
||||
}
|
||||
|
||||
//if(crouch){
|
||||
if (!Physics.SphereCast (p1, charCtrl.radius, transform.up, hit, standartHeight)) {
|
||||
if(inputJump && crouch){
|
||||
crouch = false;
|
||||
}
|
||||
if(Running && crouch){
|
||||
crouch = false;
|
||||
}
|
||||
if(crouch){
|
||||
canStand = true;
|
||||
}
|
||||
canStandCrouch = true;
|
||||
}else{
|
||||
if(crouch){
|
||||
canStand = false;
|
||||
}
|
||||
canStandCrouch = false;
|
||||
//print("We hit something");
|
||||
}
|
||||
//}
|
||||
|
||||
if(crouch && !prone){
|
||||
if(controller.height < movement.crouchHeight+0.01 && controller.height > movement.crouchHeight-0.01)
|
||||
return;
|
||||
controller.height = Mathf.Lerp(controller.height, movement.crouchHeight, Time.deltaTime/movement.crouchSmooth);
|
||||
controller.center.y = Mathf.Lerp(controller.center.y, movement.crouchHeight/2, Time.deltaTime/movement.crouchSmooth);
|
||||
lookObj.transform.localPosition.y = Mathf.Lerp(lookObj.transform.localPosition.y, movement.crouchHeight, Time.deltaTime/movement.crouchSmooth);
|
||||
movement.maxForwardSpeed = movement.CrouchSpeed;
|
||||
movement.maxSidewaysSpeed = movement.CrouchSpeed;
|
||||
movement.maxBackwardsSpeed = movement.CrouchSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
function OnRunning (){
|
||||
Running = true;
|
||||
movement.maxForwardSpeed = movement.RunSpeed;
|
||||
movement.maxSidewaysSpeed = movement.RunSpeed;
|
||||
//Make bigger extra height when player run to increase jump distance
|
||||
jumping.extraHeight = jumping.baseHeight + 0.15;
|
||||
}
|
||||
|
||||
function OffRunning (){
|
||||
Running = false;
|
||||
if(crouch || prone)
|
||||
return;
|
||||
movement.maxForwardSpeed = movement.WalkSpeed;
|
||||
movement.maxSidewaysSpeed = movement.WalkSpeed;
|
||||
movement.maxBackwardsSpeed = movement.WalkSpeed/2;
|
||||
//Change extraheight value to default when player walk
|
||||
jumping.extraHeight = jumping.baseHeight;
|
||||
}
|
||||
|
||||
//Ladder functions
|
||||
function OnLadder () {
|
||||
onLadder = true;
|
||||
//moveDirection = Vector3.zero;
|
||||
inputMoveDirection = Vector3.zero;
|
||||
//Disable gravity when climb on ladder
|
||||
movement.enableGravity = false;
|
||||
}
|
||||
|
||||
function OffLadder (ladderMovement) {
|
||||
onLadder = false;
|
||||
// perform off-ladder hop
|
||||
var hop : Vector3 = mainCamera.transform.forward;
|
||||
hop = transform.TransformDirection(hop);
|
||||
//Enable gravity when climb off ladder
|
||||
movement.enableGravity = true;
|
||||
}
|
||||
|
||||
private function ApplyInputVelocityChange (velocity : Vector3) {
|
||||
if (!canControl)
|
||||
inputMoveDirection = Vector3.zero;
|
||||
|
||||
// Find desired velocity
|
||||
var desiredVelocity : Vector3;
|
||||
if (grounded && TooSteep()) {
|
||||
// The direction we're sliding in
|
||||
desiredVelocity = Vector3(groundNormal.x, 0, groundNormal.z).normalized;
|
||||
// Find the input movement direction projected onto the sliding direction
|
||||
var projectedMoveDir = Vector3.Project(inputMoveDirection, desiredVelocity);
|
||||
// Add the sliding direction, the spped control, and the sideways control vectors
|
||||
desiredVelocity = desiredVelocity + projectedMoveDir * sliding.speedControl + (inputMoveDirection - projectedMoveDir) * sliding.sidewaysControl;
|
||||
// Multiply with the sliding speed
|
||||
desiredVelocity *= sliding.slidingSpeed;
|
||||
}
|
||||
else
|
||||
desiredVelocity = GetDesiredHorizontalVelocity();
|
||||
|
||||
if (movingPlatform.enabled && movingPlatform.movementTransfer == FPSMovementTransferOnJump.PermaTransfer) {
|
||||
desiredVelocity += movement.frameVelocity;
|
||||
desiredVelocity.y = 0;
|
||||
}
|
||||
|
||||
if (grounded)
|
||||
desiredVelocity = AdjustGroundVelocityToNormal(desiredVelocity, groundNormal);
|
||||
else
|
||||
velocity.y = 0;
|
||||
|
||||
// Enforce max velocity change
|
||||
var maxVelocityChange : float = GetMaxAcceleration(grounded) * Time.deltaTime;
|
||||
var velocityChangeVector : Vector3 = (desiredVelocity - velocity);
|
||||
if (velocityChangeVector.sqrMagnitude > maxVelocityChange * maxVelocityChange) {
|
||||
velocityChangeVector = velocityChangeVector.normalized * maxVelocityChange;
|
||||
}
|
||||
// If we're in the air and don't have control, don't apply any velocity change at all.
|
||||
// If we're on the ground and don't have control we do apply it - it will correspond to friction.
|
||||
if (grounded || canControl)
|
||||
velocity += velocityChangeVector;
|
||||
|
||||
if (grounded) {
|
||||
// When going uphill, the CharacterController will automatically move up by the needed amount.
|
||||
// Not moving it upwards manually prevent risk of lifting off from the ground.
|
||||
// When going downhill, DO move down manually, as gravity is not enough on steep hills.
|
||||
velocity.y = Mathf.Min(velocity.y, 0);
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
private function ApplyGravityAndJumping (velocity : Vector3) {
|
||||
|
||||
if (!inputJump || !canControl) {
|
||||
jumping.holdingJumpButton = false;
|
||||
jumping.lastButtonDownTime = -100;
|
||||
}
|
||||
|
||||
if (inputJump && jumping.lastButtonDownTime < 0 && canControl)
|
||||
jumping.lastButtonDownTime = Time.time;
|
||||
|
||||
if (grounded)
|
||||
velocity.y = Mathf.Min(0, velocity.y) - movement.gravity * Time.deltaTime;
|
||||
else {
|
||||
velocity.y = movement.velocity.y - movement.gravity * Time.deltaTime;
|
||||
|
||||
// When jumping up we don't apply gravity for some time when the user is holding the jump button.
|
||||
// This gives more control over jump height by pressing the button longer.
|
||||
if (jumping.jumping && jumping.holdingJumpButton) {
|
||||
// Calculate the duration that the extra jump force should have effect.
|
||||
// If we're still less than that duration after the jumping time, apply the force.
|
||||
if (Time.time < jumping.lastStartTime + jumping.extraHeight / CalculateJumpVerticalSpeed(jumping.baseHeight)) {
|
||||
// Negate the gravity we just applied, except we push in jumpDir rather than jump upwards.
|
||||
velocity += jumping.jumpDir * movement.gravity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we don't fall any faster than maxFallSpeed. This gives our character a terminal velocity.
|
||||
velocity.y = Mathf.Max (velocity.y, -movement.maxFallSpeed);
|
||||
}
|
||||
|
||||
if (grounded) {
|
||||
// Jump only if the jump button was pressed down in the last 0.2 seconds.
|
||||
// We use this check instead of checking if it's pressed down right now
|
||||
// because players will often try to jump in the exact moment when hitting the ground after a jump
|
||||
// and if they hit the button a fraction of a second too soon and no new jump happens as a consequence,
|
||||
// it's confusing and it feels like the game is buggy.
|
||||
if (jumping.enabled && canControl && (Time.time - jumping.lastButtonDownTime < 0.2)) {
|
||||
grounded = false;
|
||||
jumping.jumping = true;
|
||||
jumping.lastStartTime = Time.time;
|
||||
jumping.lastButtonDownTime = -100;
|
||||
jumping.holdingJumpButton = true;
|
||||
|
||||
// Calculate the jumping direction
|
||||
if (TooSteep())
|
||||
jumping.jumpDir = Vector3.Slerp(Vector3.up, groundNormal, jumping.steepPerpAmount);
|
||||
else
|
||||
jumping.jumpDir = Vector3.Slerp(Vector3.up, groundNormal, jumping.perpAmount);
|
||||
|
||||
// Apply the jumping force to the velocity. Cancel any vertical velocity first.
|
||||
velocity.y = 0;
|
||||
velocity += jumping.jumpDir * CalculateJumpVerticalSpeed (jumping.baseHeight);
|
||||
|
||||
// Apply inertia from platform
|
||||
if (movingPlatform.enabled &&
|
||||
(movingPlatform.movementTransfer == FPSMovementTransferOnJump.InitTransfer ||
|
||||
movingPlatform.movementTransfer == FPSMovementTransferOnJump.PermaTransfer)
|
||||
) {
|
||||
movement.frameVelocity = movingPlatform.platformVelocity;
|
||||
velocity += movingPlatform.platformVelocity;
|
||||
}
|
||||
|
||||
SendMessage("OnJump", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
else {
|
||||
jumping.holdingJumpButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
function OnControllerColliderHit (hit : ControllerColliderHit) {
|
||||
if (hit.normal.y > 0 && hit.normal.y > groundNormal.y && hit.moveDirection.y < 0) {
|
||||
if ((hit.point - movement.lastHitPoint).sqrMagnitude > 0.001 || lastGroundNormal == Vector3.zero)
|
||||
groundNormal = hit.normal;
|
||||
else
|
||||
groundNormal = lastGroundNormal;
|
||||
|
||||
movingPlatform.hitPlatform = hit.collider.transform;
|
||||
movement.hitPoint = hit.point;
|
||||
movement.frameVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
//Did we push something?
|
||||
if(pushing.canPush){
|
||||
var body : Rigidbody = hit.collider.attachedRigidbody;
|
||||
// no rigidbody
|
||||
if (body == null || body.isKinematic)
|
||||
return;
|
||||
|
||||
// We dont want to push objects below us
|
||||
if (hit.moveDirection.y < -0.3)
|
||||
return;
|
||||
|
||||
// Calculate push direction from move direction,
|
||||
// we only push objects to the sides never up and down
|
||||
var pushDir : Vector3 = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
|
||||
|
||||
// If you know how fast your character is trying to move,
|
||||
// then you can also multiply the push velocity by that.
|
||||
|
||||
// Apply the push
|
||||
body.velocity = pushDir * pushing.pushPower;
|
||||
}
|
||||
}
|
||||
|
||||
private function SubtractNewPlatformVelocity () {
|
||||
// When landing, subtract the velocity of the new ground from the character's velocity
|
||||
// since movement in ground is relative to the movement of the ground.
|
||||
if (movingPlatform.enabled &&
|
||||
(movingPlatform.movementTransfer == FPSMovementTransferOnJump.InitTransfer ||
|
||||
movingPlatform.movementTransfer == FPSMovementTransferOnJump.PermaTransfer)
|
||||
) {
|
||||
// If we landed on a new platform, we have to wait for two FixedUpdates
|
||||
// before we know the velocity of the platform under the character
|
||||
if (movingPlatform.newPlatform) {
|
||||
var platform : Transform = movingPlatform.activePlatform;
|
||||
yield WaitForFixedUpdate();
|
||||
yield WaitForFixedUpdate();
|
||||
if (grounded && platform == movingPlatform.activePlatform)
|
||||
yield 1;
|
||||
}
|
||||
movement.velocity -= movingPlatform.platformVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
private function MoveWithPlatform () : boolean {
|
||||
return (
|
||||
movingPlatform.enabled
|
||||
&& (grounded || movingPlatform.movementTransfer == FPSMovementTransferOnJump.PermaLocked)
|
||||
&& movingPlatform.activePlatform != null
|
||||
);
|
||||
}
|
||||
|
||||
private function GetDesiredHorizontalVelocity () {
|
||||
// Find desired velocity
|
||||
var desiredLocalDirection : Vector3 = tr.InverseTransformDirection(inputMoveDirection);
|
||||
var maxSpeed : float = MaxSpeedInDirection(desiredLocalDirection);
|
||||
if (grounded) {
|
||||
// Modify max speed on slopes based on slope speed multiplier curve
|
||||
var movementSlopeAngle = Mathf.Asin(movement.velocity.normalized.y) * Mathf.Rad2Deg;
|
||||
maxSpeed *= movement.slopeSpeedMultiplier.Evaluate(movementSlopeAngle);
|
||||
}
|
||||
return tr.TransformDirection(desiredLocalDirection * maxSpeed);
|
||||
}
|
||||
|
||||
private function AdjustGroundVelocityToNormal (hVelocity : Vector3, groundNormal : Vector3) : Vector3 {
|
||||
var sideways : Vector3 = Vector3.Cross(Vector3.up, hVelocity);
|
||||
return Vector3.Cross(sideways, groundNormal).normalized * hVelocity.magnitude;
|
||||
}
|
||||
|
||||
private function IsGroundedTest () {
|
||||
return (groundNormal.y > 0.01);
|
||||
}
|
||||
|
||||
function GetMaxAcceleration (grounded : boolean) : float {
|
||||
// Maximum acceleration on ground and in air
|
||||
if (grounded)
|
||||
return movement.maxGroundAcceleration;
|
||||
else
|
||||
return movement.maxAirAcceleration;
|
||||
}
|
||||
|
||||
function CalculateJumpVerticalSpeed (targetJumpHeight : float) {
|
||||
// From the jump height and gravity we deduce the upwards speed
|
||||
// for the character to reach at the apex.
|
||||
return Mathf.Sqrt (2 * targetJumpHeight * movement.gravity);
|
||||
}
|
||||
|
||||
function IsJumping () {
|
||||
return jumping.jumping;
|
||||
}
|
||||
|
||||
function IsSliding () {
|
||||
return (grounded && sliding.enabled && TooSteep());
|
||||
}
|
||||
|
||||
function IsTouchingCeiling () {
|
||||
return (movement.collisionFlags & CollisionFlags.CollidedAbove) != 0;
|
||||
}
|
||||
|
||||
function IsGrounded () {
|
||||
return grounded;
|
||||
}
|
||||
|
||||
function TooSteep () {
|
||||
return (groundNormal.y <= Mathf.Cos(controller.slopeLimit * Mathf.Deg2Rad));
|
||||
}
|
||||
|
||||
function GetDirection () {
|
||||
return inputMoveDirection;
|
||||
}
|
||||
|
||||
function SetControllable (controllable : boolean) {
|
||||
canControl = controllable;
|
||||
}
|
||||
|
||||
// Project a direction onto elliptical quater segments based on forward, sideways, and backwards speed.
|
||||
// The function returns the length of the resulting vector.
|
||||
function MaxSpeedInDirection (desiredMovementDirection : Vector3) : float {
|
||||
if (desiredMovementDirection == Vector3.zero)
|
||||
return 0;
|
||||
else {
|
||||
var zAxisEllipseMultiplier : float = (desiredMovementDirection.z > 0 ? movement.maxForwardSpeed : movement.maxBackwardsSpeed) / movement.maxSidewaysSpeed;
|
||||
var temp : Vector3 = new Vector3(desiredMovementDirection.x, 0, desiredMovementDirection.z / zAxisEllipseMultiplier).normalized;
|
||||
var length : float = new Vector3(temp.x, 0, temp.z * zAxisEllipseMultiplier).magnitude * movement.maxSidewaysSpeed;
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
function SetVelocity (velocity : Vector3) {
|
||||
grounded = false;
|
||||
movement.velocity = velocity;
|
||||
movement.frameVelocity = Vector3.zero;
|
||||
SendMessage("OnExternalVelocity");
|
||||
}
|
||||
|
||||
// Require a character controller to be attached to the same game object
|
||||
@script RequireComponent (CharacterController)
|
||||
@script AddComponentMenu ("FPS system/Character/FPS Controller")
|
||||
@script RequireComponent (FPSinput)
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d2eced27ba55304daffb08ee0b2eab9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,45 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
private var motor : FPScontroller;
|
||||
|
||||
// Use this for initialization
|
||||
function Awake () {
|
||||
motor = GetComponent(FPScontroller);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
function LateUpdate () {
|
||||
// Get the input vector from kayboard or analog stick
|
||||
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
||||
|
||||
if (directionVector != Vector3.zero) {
|
||||
// Get the length of the directon vector and then normalize it
|
||||
// Dividing by the length is cheaper than normalizing when we already have the length anyway
|
||||
var directionLength = directionVector.magnitude;
|
||||
directionVector = directionVector / directionLength;
|
||||
|
||||
// Make sure the length is no bigger than 1
|
||||
directionLength = Mathf.Min(1, directionLength);
|
||||
|
||||
// Make the input vector more sensitive towards the extremes and less sensitive in the middle
|
||||
// This makes it easier to control slow speeds when using analog sticks
|
||||
directionLength = directionLength * directionLength;
|
||||
|
||||
// Multiply the normalized direction vector by the modified length
|
||||
directionVector = directionVector * directionLength;
|
||||
}
|
||||
|
||||
// Apply the direction to the CharacterMotor
|
||||
motor.inputMoveDirection = transform.rotation * directionVector;
|
||||
motor.inputJump = Input.GetKeyDown(KeyCode.Space);
|
||||
|
||||
//Run Input
|
||||
motor.inputRun = Input.GetKey(KeyCode.LeftShift);
|
||||
|
||||
//Crouch Input
|
||||
motor.inputCrouch = Input.GetKeyDown(KeyCode.C);
|
||||
|
||||
//Prone Input
|
||||
motor.inputProne = Input.GetKeyDown(KeyCode.LeftControl);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5385a2613b23724598b5e253a9acf82
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 607b5454f4590f749b720434c2d98d01
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,23 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
//Attach this script to a ladder object, add collider to it and mark "trigger"
|
||||
//and dont forget to tag it "Ladder"
|
||||
//make 2 GameObjects rename them to LadderTop and LadderBottom
|
||||
//and place relative in bottom and top of ladder
|
||||
//Assign that objects on ladderBottom and ladderTop variables
|
||||
var ladderBottom : GameObject;
|
||||
var ladderTop : GameObject;
|
||||
|
||||
private var climbDirection : Vector3 = Vector3.zero;
|
||||
|
||||
function Start () {
|
||||
climbDirection = ladderTop.transform.position - ladderBottom.transform.position;
|
||||
}
|
||||
|
||||
function ClimbDirection () {
|
||||
return climbDirection;
|
||||
}
|
||||
|
||||
@script AddComponentMenu("FPS system/Ladder System/Attach to Ladder")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5f0beca586be4a43825f93f2a3c3189
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,120 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
// The speed of the player up and down the ladder. Roughly equal to walking speed is a good starting point.
|
||||
var climbSpeed = 6.0;
|
||||
// In the range -1 to 1 where -1 == -90 deg, 1 = 90 deg, angle of view camera at which the user climbs down rather than up when moving with the forward key.
|
||||
var climbDownThreshold = -0.4;
|
||||
|
||||
//Private vars
|
||||
private var climbDirection : Vector3 = Vector3.zero;
|
||||
private var lateralMove : Vector3 = Vector3.zero;
|
||||
private var forwardMove : Vector3 = Vector3.zero;
|
||||
private var ladderMovement : Vector3 = Vector3.zero;
|
||||
private var currentLadder : Ladder = null;
|
||||
private var latchedToLadder : boolean = false;
|
||||
private var inLandingPad : boolean = false;
|
||||
private var mainCamera : GameObject = null;
|
||||
private var controller : CharacterController = null;
|
||||
private var landingPads : ArrayList = null;
|
||||
private var trigger : boolean = false;
|
||||
|
||||
|
||||
function Start () {
|
||||
mainCamera = GameObject.FindWithTag("MainCamera");
|
||||
controller = GetComponent(CharacterController);
|
||||
landingPads = new ArrayList();
|
||||
}
|
||||
|
||||
function OnTriggerEnter (other : Collider) {
|
||||
if(other.tag == "Ladder") {
|
||||
LatchLadder(other.gameObject, other);
|
||||
trigger = true;
|
||||
}
|
||||
}
|
||||
|
||||
function OnTriggerExit () {
|
||||
|
||||
// UnlatchLadder();
|
||||
// print("WTF");
|
||||
}
|
||||
|
||||
//Connect the player to the ladder, and shunt FixedUpdate calls to the special ladder movment functions.
|
||||
function LatchLadder (latchedLadder : GameObject, collisionWaypoint : Collider) {
|
||||
// typecast the latchedLadder as a Ladder object from GameObject
|
||||
currentLadder = latchedLadder.GetComponent(Ladder);
|
||||
latchedToLadder = true;
|
||||
|
||||
// get the climb direction
|
||||
climbDirection = currentLadder.ClimbDirection();
|
||||
|
||||
// let the other scripts know we are on the ladder now
|
||||
gameObject.SendMessage("OnLadder", null, SendMessageOptions.RequireReceiver);
|
||||
}
|
||||
|
||||
|
||||
//Shut off special ladder movement controls and return to normal movement operations.
|
||||
function UnlatchLadder () {
|
||||
latchedToLadder = false;
|
||||
currentLadder = null;
|
||||
|
||||
// let the other scripts know we are off the ladder now
|
||||
gameObject.SendMessage("OffLadder", ladderMovement, SendMessageOptions.RequireReceiver);
|
||||
}
|
||||
|
||||
|
||||
//Convert the player's normal forward and backward motion into up and down motion on the ladder.
|
||||
function FixedUpdate () {
|
||||
if(!latchedToLadder)
|
||||
return;
|
||||
|
||||
if(trigger){
|
||||
RaycastCheck ();
|
||||
}
|
||||
|
||||
// If we jumpped, then revert back to the original behavior
|
||||
if (Input.GetButton("Jump")) {
|
||||
UnlatchLadder();
|
||||
//gameObject.SendMessage("FixedUpdate", null, SendMessageOptions.RequireReceiver);
|
||||
return;
|
||||
}
|
||||
|
||||
// find the climbing direction
|
||||
var verticalMove = climbDirection.normalized;
|
||||
|
||||
// convert forward motion to vertical motion
|
||||
verticalMove *= Input.GetAxis("Vertical");
|
||||
verticalMove *= (mainCamera.transform.forward.y > climbDownThreshold) ? 1 : -1;
|
||||
|
||||
// find lateral component of motion
|
||||
if (inLandingPad) {
|
||||
lateralMove = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
||||
} else {
|
||||
lateralMove = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
|
||||
}
|
||||
lateralMove = transform.TransformDirection(lateralMove);
|
||||
|
||||
// move
|
||||
ladderMovement = verticalMove + lateralMove;
|
||||
var flags = controller.Move(ladderMovement * climbSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
function RaycastCheck () {
|
||||
var hit : RaycastHit;
|
||||
var charContr : CharacterController = GetComponent(CharacterController);
|
||||
var p1 : Vector3 = transform.position + charContr.center +
|
||||
Vector3.up * (-charContr.height*0.5);
|
||||
var p2 : Vector3 = p1 + Vector3.up * charContr.height;
|
||||
// Cast character controller shape 10 meters forward, to see if it is about to hit anything
|
||||
if (Physics.CapsuleCast (p1, p2, charContr.radius, transform.forward, hit, charContr.radius)) {
|
||||
|
||||
}else{
|
||||
UnlatchLadder();
|
||||
trigger = false;
|
||||
}
|
||||
}
|
||||
|
||||
@script RequireComponent(CharacterController)
|
||||
@script AddComponentMenu("FPS system/Ladder System/Attach to Player")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6f61fa7e22dc495c82daf17e3e0ee00
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a21c0f800a6f184f88143255909e59d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -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:
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c40da21aa4633f448a954376be07f16
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,70 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
//This script is used for multiplayer, for displaying other players name
|
||||
//It should be enable for every player but not for our
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
public class DrawPlayerName : MonoBehaviour {
|
||||
|
||||
public GUISkin guiSKin;
|
||||
public Transform positionDisplay;
|
||||
//Use this ti display player current hp
|
||||
public Texture2D hpLine;
|
||||
string playerName;
|
||||
|
||||
|
||||
//Find player damage which attached to the same game object as this script
|
||||
//We need to this to display player hp line under name
|
||||
PlayerDamage pd;
|
||||
|
||||
|
||||
void Awake(){
|
||||
pd = gameObject.GetComponent<PlayerDamage>();
|
||||
if(!positionDisplay){
|
||||
positionDisplay = transform;
|
||||
}
|
||||
}
|
||||
|
||||
void Update(){
|
||||
playerName = gameObject.name;
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
GUI.skin = guiSKin;
|
||||
GUI.depth = 2;
|
||||
float offset = new float();
|
||||
|
||||
GUI.color = new Color(0.1f,0.9f,0.5f,1);
|
||||
if(Camera.main){
|
||||
Vector3 screenPos = Camera.main.WorldToScreenPoint(positionDisplay.position);
|
||||
if((float)(screenPos.z*3) < 50){
|
||||
offset = screenPos.z*3;
|
||||
}else{
|
||||
offset = 50;
|
||||
}
|
||||
|
||||
if(screenPos.z >0){
|
||||
//Display player name
|
||||
GUI.Label(new Rect(screenPos.x-100, Screen.height-screenPos.y-5-offset, 200, 30), playerName);
|
||||
//Display player health (hp)
|
||||
if(pd.currentHp > 60){
|
||||
GUI.color = Color.green;
|
||||
}else{
|
||||
if(pd.currentHp > 30){
|
||||
GUI.color = Color.yellow;
|
||||
}else{
|
||||
GUI.color = Color.red;
|
||||
}
|
||||
}
|
||||
//Background box
|
||||
GUI.Box(new Rect(screenPos.x-pd.hp/2, Screen.height-screenPos.y+25-offset, pd.hp, 5), "");
|
||||
//Player hp
|
||||
GUI.DrawTexture(new Rect(screenPos.x-pd.hp/2, Screen.height-screenPos.y+25-offset, pd.currentHp, 5), hpLine, ScaleMode.StretchToFill);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaf8b97a71279ac4d92cdcb7e8f331fc
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class FramesPerSecond : MonoBehaviour {
|
||||
|
||||
//GUI
|
||||
public GUISkin guiStyle;
|
||||
|
||||
public float updateInterval = 0.5f;
|
||||
private float accum = 0.0f;
|
||||
private int frames = 0;
|
||||
private float timeleft;
|
||||
public string fps;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
timeleft = updateInterval;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
timeleft -= Time.deltaTime;
|
||||
accum += Time.timeScale/Time.deltaTime;
|
||||
++frames;
|
||||
|
||||
// Interval ended - update GUI text and start new interval
|
||||
if( timeleft <= 0.0 ) {
|
||||
// display two fractional digits (f2 format)
|
||||
fps = "" + (accum/frames).ToString("f2");
|
||||
timeleft = updateInterval;
|
||||
accum = 0.0f;
|
||||
frames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI () {
|
||||
GUI.skin = guiStyle;
|
||||
// GUI.Label(new Rect (Screen.width-75, 5, 70, 20), "FPS " + fps);
|
||||
GUI.Label(new Rect (Screen.width-70, 35, 60, 30), fps);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52b9c0ccbd478964fa819fdaa93f1ea8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,218 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
[System.Serializable]
|
||||
public class BendingSegment {
|
||||
public Transform firstTransform;
|
||||
public Transform lastTransform;
|
||||
public float thresholdAngleDifference = 0;
|
||||
public float bendingMultiplier = 0.6f;
|
||||
public float maxAngleDifference = 30;
|
||||
public float maxBendingAngle = 80;
|
||||
public float responsiveness = 5;
|
||||
internal float angleH;
|
||||
internal float angleV;
|
||||
internal Vector3 dirUp;
|
||||
internal Vector3 referenceLookDir;
|
||||
internal Vector3 referenceUpDir;
|
||||
internal int chainLength;
|
||||
internal Quaternion[] origRotations;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class NonAffectedJoints {
|
||||
public Transform joint;
|
||||
public float effect = 0;
|
||||
}
|
||||
|
||||
public class HeadLookController : MonoBehaviour {
|
||||
|
||||
public Transform rootNode;
|
||||
public BendingSegment[] segments;
|
||||
public NonAffectedJoints[] nonAffectedJoints;
|
||||
public Vector3 headLookVector = Vector3.forward;
|
||||
public Vector3 headUpVector = Vector3.up;
|
||||
public Transform target;
|
||||
public float effect = 1;
|
||||
public bool overrideAnimation = false;
|
||||
|
||||
void Start () {
|
||||
if (rootNode == null) {
|
||||
rootNode = transform;
|
||||
}
|
||||
|
||||
// Setup segments
|
||||
foreach (BendingSegment segment in segments) {
|
||||
Quaternion parentRot = segment.firstTransform.parent.rotation;
|
||||
Quaternion parentRotInv = Quaternion.Inverse(parentRot);
|
||||
segment.referenceLookDir =
|
||||
parentRotInv * rootNode.rotation * headLookVector.normalized;
|
||||
segment.referenceUpDir =
|
||||
parentRotInv * rootNode.rotation * headUpVector.normalized;
|
||||
segment.angleH = 0;
|
||||
segment.angleV = 0;
|
||||
segment.dirUp = segment.referenceUpDir;
|
||||
|
||||
segment.chainLength = 1;
|
||||
Transform t = segment.lastTransform;
|
||||
while (t != segment.firstTransform && t != t.root) {
|
||||
segment.chainLength++;
|
||||
t = t.parent;
|
||||
}
|
||||
|
||||
segment.origRotations = new Quaternion[segment.chainLength];
|
||||
t = segment.lastTransform;
|
||||
for (int i=segment.chainLength-1; i>=0; i--) {
|
||||
segment.origRotations[i] = t.localRotation;
|
||||
t = t.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate () {
|
||||
if (Time.deltaTime == 0)
|
||||
return;
|
||||
|
||||
// Remember initial directions of joints that should not be affected
|
||||
Vector3[] jointDirections = new Vector3[nonAffectedJoints.Length];
|
||||
for (int i=0; i<nonAffectedJoints.Length; i++) {
|
||||
foreach (Transform child in nonAffectedJoints[i].joint) {
|
||||
jointDirections[i] = child.position - nonAffectedJoints[i].joint.position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle each segment
|
||||
foreach (BendingSegment segment in segments) {
|
||||
Transform t = segment.lastTransform;
|
||||
if (overrideAnimation) {
|
||||
for (int i=segment.chainLength-1; i>=0; i--) {
|
||||
t.localRotation = segment.origRotations[i];
|
||||
t = t.parent;
|
||||
}
|
||||
}
|
||||
|
||||
Quaternion parentRot = segment.firstTransform.parent.rotation;
|
||||
Quaternion parentRotInv = Quaternion.Inverse(parentRot);
|
||||
|
||||
// Desired look direction in world space
|
||||
Vector3 lookDirWorld = (target.position - segment.lastTransform.position).normalized;
|
||||
|
||||
// Desired look directions in neck parent space
|
||||
Vector3 lookDirGoal = (parentRotInv * lookDirWorld);
|
||||
|
||||
// Get the horizontal and vertical rotation angle to look at the target
|
||||
float hAngle = AngleAroundAxis(
|
||||
segment.referenceLookDir, lookDirGoal, segment.referenceUpDir
|
||||
);
|
||||
|
||||
Vector3 rightOfTarget = Vector3.Cross(segment.referenceUpDir, lookDirGoal);
|
||||
|
||||
Vector3 lookDirGoalinHPlane =
|
||||
lookDirGoal - Vector3.Project(lookDirGoal, segment.referenceUpDir);
|
||||
|
||||
float vAngle = AngleAroundAxis(
|
||||
lookDirGoalinHPlane, lookDirGoal, rightOfTarget
|
||||
);
|
||||
|
||||
// Handle threshold angle difference, bending multiplier,
|
||||
// and max angle difference here
|
||||
float hAngleThr = Mathf.Max(
|
||||
0, Mathf.Abs(hAngle) - segment.thresholdAngleDifference
|
||||
) * Mathf.Sign(hAngle);
|
||||
|
||||
float vAngleThr = Mathf.Max(
|
||||
0, Mathf.Abs(vAngle) - segment.thresholdAngleDifference
|
||||
) * Mathf.Sign(vAngle);
|
||||
|
||||
hAngle = Mathf.Max(
|
||||
Mathf.Abs(hAngleThr) * Mathf.Abs(segment.bendingMultiplier),
|
||||
Mathf.Abs(hAngle) - segment.maxAngleDifference
|
||||
) * Mathf.Sign(hAngle) * Mathf.Sign(segment.bendingMultiplier);
|
||||
|
||||
vAngle = Mathf.Max(
|
||||
Mathf.Abs(vAngleThr) * Mathf.Abs(segment.bendingMultiplier),
|
||||
Mathf.Abs(vAngle) - segment.maxAngleDifference
|
||||
) * Mathf.Sign(vAngle) * Mathf.Sign(segment.bendingMultiplier);
|
||||
|
||||
// Handle max bending angle here
|
||||
hAngle = Mathf.Clamp(hAngle, -segment.maxBendingAngle, segment.maxBendingAngle);
|
||||
vAngle = Mathf.Clamp(vAngle, -segment.maxBendingAngle, segment.maxBendingAngle);
|
||||
|
||||
Vector3 referenceRightDir =
|
||||
Vector3.Cross(segment.referenceUpDir, segment.referenceLookDir);
|
||||
|
||||
// Lerp angles
|
||||
segment.angleH = Mathf.Lerp(
|
||||
segment.angleH, hAngle, Time.deltaTime * segment.responsiveness
|
||||
);
|
||||
segment.angleV = Mathf.Lerp(
|
||||
segment.angleV, vAngle, Time.deltaTime * segment.responsiveness
|
||||
);
|
||||
|
||||
// Get direction
|
||||
lookDirGoal = Quaternion.AngleAxis(segment.angleH, segment.referenceUpDir)
|
||||
* Quaternion.AngleAxis(segment.angleV, referenceRightDir)
|
||||
* segment.referenceLookDir;
|
||||
|
||||
// Make look and up perpendicular
|
||||
Vector3 upDirGoal = segment.referenceUpDir;
|
||||
Vector3.OrthoNormalize(ref lookDirGoal, ref upDirGoal);
|
||||
|
||||
// Interpolated look and up directions in neck parent space
|
||||
Vector3 lookDir = lookDirGoal;
|
||||
segment.dirUp = Vector3.Slerp(segment.dirUp, upDirGoal, Time.deltaTime*5);
|
||||
Vector3.OrthoNormalize(ref lookDir, ref segment.dirUp);
|
||||
|
||||
// Look rotation in world space
|
||||
Quaternion lookRot = (
|
||||
(parentRot * Quaternion.LookRotation(lookDir, segment.dirUp))
|
||||
* Quaternion.Inverse(
|
||||
parentRot * Quaternion.LookRotation(
|
||||
segment.referenceLookDir, segment.referenceUpDir
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Distribute rotation over all joints in segment
|
||||
Quaternion dividedRotation =
|
||||
Quaternion.Slerp(Quaternion.identity, lookRot, effect / segment.chainLength);
|
||||
t = segment.lastTransform;
|
||||
for (int i=0; i<segment.chainLength; i++) {
|
||||
t.rotation = dividedRotation * t.rotation;
|
||||
t = t.parent;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle non affected joints
|
||||
for (int i=0; i<nonAffectedJoints.Length; i++) {
|
||||
Vector3 newJointDirection = Vector3.zero;
|
||||
|
||||
foreach (Transform child in nonAffectedJoints[i].joint) {
|
||||
newJointDirection = child.position - nonAffectedJoints[i].joint.position;
|
||||
break;
|
||||
}
|
||||
|
||||
Vector3 combinedJointDirection = Vector3.Slerp(
|
||||
jointDirections[i], newJointDirection, nonAffectedJoints[i].effect
|
||||
);
|
||||
|
||||
nonAffectedJoints[i].joint.rotation = Quaternion.FromToRotation(
|
||||
newJointDirection, combinedJointDirection
|
||||
) * nonAffectedJoints[i].joint.rotation;
|
||||
}
|
||||
}
|
||||
|
||||
// The angle between dirA and dirB around axis
|
||||
public static float AngleAroundAxis (Vector3 dirA, Vector3 dirB, Vector3 axis) {
|
||||
// Project A and B onto the plane orthogonal target axis
|
||||
dirA = dirA - Vector3.Project(dirA, axis);
|
||||
dirB = dirB - Vector3.Project(dirB, axis);
|
||||
|
||||
// Find (positive) angle between A and B
|
||||
float angle = Vector3.Angle(dirA, dirB);
|
||||
|
||||
// Return angle multiplied with 1 or -1
|
||||
return angle * (Vector3.Dot(axis, Vector3.Cross(dirA, dirB)) < 0 ? -1 : 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b707d709a916b024a9227027be6d5961
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,55 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0 + Multiplayer
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class RagdollController : MonoBehaviour {
|
||||
|
||||
public GUISkin guiSKin;
|
||||
public GameObject cam;
|
||||
//make rigidbody kinematic after
|
||||
//also it is used as Wait For respawn time
|
||||
public int timer;
|
||||
//Display timer gui or not
|
||||
bool gui;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
StartCoroutine(sleepRigidbody());
|
||||
}
|
||||
|
||||
void OnGUI(){
|
||||
if(gui && cam){
|
||||
GUI.skin = guiSKin;
|
||||
GUI.Label(new Rect(Screen.width/2-75, Screen.height/2-15, 150, 30), "Respawn in: " + timer);
|
||||
}
|
||||
}
|
||||
|
||||
//Respawn in 3 seconds
|
||||
void RespawnAfter(){
|
||||
gui = true;
|
||||
InvokeRepeating("_respawnAfter", 1, 1);
|
||||
}
|
||||
|
||||
void _respawnAfter () {
|
||||
timer --;
|
||||
if(timer == 0){
|
||||
clearCamera();
|
||||
GameObject.FindWithTag("Network").SendMessage("SpawnPlayer");
|
||||
Destroy (this);
|
||||
}
|
||||
}
|
||||
|
||||
void clearCamera(){
|
||||
Destroy(cam);
|
||||
}
|
||||
|
||||
IEnumerator sleepRigidbody(){
|
||||
//Make ragdoll kinematic
|
||||
yield return new WaitForSeconds(timer);
|
||||
foreach(Rigidbody c in transform.root.GetComponentsInChildren<Rigidbody>()){
|
||||
c.isKinematic = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36fee6e682f9a0b47b259513532fbc17
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d0f74bb510ada04dacc17d4a6d0677b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,56 @@
|
||||
//EnableHelper used to interact between C# and JS
|
||||
//Create empty game object and tag it "EnableHelper"
|
||||
//When this object active, assigned scripts are enabled
|
||||
//Once we deactivate this object, all script become disabled aswell
|
||||
//Usefull for pausing game without changing timeScale
|
||||
|
||||
#pragma strict
|
||||
import System.Collections.Generic;
|
||||
|
||||
var fpsController : FPScontroller;
|
||||
var weaponManager : WeaponManager;
|
||||
//Assign 2 mouse looks
|
||||
var mouseLook1 : FPSMouseLook;
|
||||
var mouseLook2 : FPSMouseLook;
|
||||
|
||||
private var enablerReferenceObject : GameObject;
|
||||
|
||||
function Start () {
|
||||
enablerReferenceObject = gameObject.FindWithTag("EnableHelper").gameObject;
|
||||
}
|
||||
|
||||
function Update () {
|
||||
//Reference object is enabled, enable all assigned scripts
|
||||
if(enablerReferenceObject && enablerReferenceObject.active == true){
|
||||
if(fpsController.canControl == false){
|
||||
fpsController.canControl = true;
|
||||
}
|
||||
if(weaponManager.enabled == false && weaponManager.SelectedWeapon && weaponManager.SelectedWeapon.enabled == false){
|
||||
weaponManager.enabled = true;
|
||||
weaponManager.SelectedWeapon.enabled = true;
|
||||
}
|
||||
if(mouseLook1.enabled == false && mouseLook2.enabled == false){
|
||||
mouseLook1.enabled = true;
|
||||
mouseLook2.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Reference object is disabled, deactivate all assigned scripts
|
||||
if(!enablerReferenceObject || enablerReferenceObject.active == false){
|
||||
if(fpsController.canControl == true ){
|
||||
fpsController.canControl = false;
|
||||
}
|
||||
if(weaponManager.enabled == true && weaponManager.SelectedWeapon && weaponManager.SelectedWeapon.enabled == true){
|
||||
weaponManager.SelectedWeapon.enabled = false;
|
||||
weaponManager.enabled = false;
|
||||
}
|
||||
if(mouseLook1.enabled == true && mouseLook2.enabled == true){
|
||||
mouseLook1.enabled = false;
|
||||
mouseLook2.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!enablerReferenceObject && gameObject.FindWithTag("EnableHelper").gameObject != null){
|
||||
enablerReferenceObject = gameObject.FindWithTag("EnableHelper").gameObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bda6d37470bc9374ba19cf642d57eb5c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,186 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
import System.Collections.Generic;
|
||||
|
||||
var guiStyle : GUISkin;
|
||||
var objective : String;
|
||||
var showTime : boolean = true;
|
||||
|
||||
@HideInInspector
|
||||
var finishedGame : boolean;
|
||||
private var weaponManager : WeaponManager;
|
||||
private var startGame : boolean = true;
|
||||
private var timer : float;
|
||||
private var mainMenu : boolean;
|
||||
private var resolutions : Resolution[];
|
||||
private var QualityNames : String[];
|
||||
private var resolutionIndex : int = 3;
|
||||
private var scroll : Vector2;
|
||||
private var scroll2 : Vector2;
|
||||
private var scroll3 : Vector2;
|
||||
private var niceTime : String;
|
||||
|
||||
function Start () {
|
||||
weaponManager = GameObject.FindWithTag("WeaponManager").GetComponent.<WeaponManager>();
|
||||
mainMenu = true;
|
||||
Invoke("Pause", 0.01);
|
||||
resolutions = Screen.resolutions;
|
||||
resolutionIndex = (resolutions.Length-1)/2;
|
||||
QualityNames = QualitySettings.names;
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if(startGame && weaponManager.SelectedWeapon){
|
||||
weaponManager.SelectedWeapon.gameObject.SetActiveRecursively(false);
|
||||
}
|
||||
if(!startGame){
|
||||
if(!finishedGame){
|
||||
timer += Time.deltaTime;
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.Tab)){
|
||||
mainMenu = !mainMenu;
|
||||
Pause();
|
||||
}
|
||||
|
||||
if(!mainMenu){
|
||||
Screen.lockCursor = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.P)){
|
||||
Screen.fullScreen = !Screen.fullScreen;
|
||||
if(!Screen.fullScreen){
|
||||
Screen.SetResolution(resolutions[resolutionIndex].width, resolutions[resolutionIndex].height, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function OnGUI(){
|
||||
GUI.skin = guiStyle;
|
||||
|
||||
GUI.color.a = 0.7;
|
||||
//Timer
|
||||
var minutes : int = Mathf.FloorToInt(timer / 60F);
|
||||
var seconds : int = Mathf.FloorToInt(timer - minutes * 60);
|
||||
niceTime = String.Format("{0:0}:{1:00}", minutes, seconds);
|
||||
if(showTime){
|
||||
if(!finishedGame){
|
||||
GUI.Box(new Rect(Screen.width/2 - 50,40,100,30), niceTime);
|
||||
}else{
|
||||
GUI.Box(new Rect(Screen.width/2 - 100,40,200,30), "Your Time | " + niceTime);
|
||||
}
|
||||
}
|
||||
|
||||
if(mainMenu){
|
||||
GUI.Window (0, Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 300), MainMenu, "Main Menu");
|
||||
GUI.Window (1, Rect (Screen.width/2-240, Screen.height/2 - 100, 150, 100), Resolutions, "Resolution");
|
||||
GUI.Window (2, Rect (Screen.width/2-85, Screen.height/2 - 100, 150, 100), QualityWindow, "Quality");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function MainMenu (windowID : int) {
|
||||
GUILayout.Space (10);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Box(resolutions[resolutionIndex].width + " x " + resolutions[resolutionIndex].height, GUILayout.Width(150), GUILayout.Height(20));
|
||||
|
||||
GUILayout.Box(QualityNames[QualitySettings.GetQualityLevel ()], GUILayout.Width(150), GUILayout.Height(20));
|
||||
|
||||
|
||||
GUILayout.Space (15);
|
||||
if(startGame){
|
||||
if(GUILayout.Button("Start Game", GUILayout.Width(150), GUILayout.Height(30))){
|
||||
startGame = false;
|
||||
mainMenu = false;
|
||||
Pause();
|
||||
weaponManager.SelectedWeapon.gameObject.SetActiveRecursively(true);
|
||||
weaponManager.TakeFirstWeapon(weaponManager.SelectedWeapon.gameObject);
|
||||
}
|
||||
}else{
|
||||
GUILayout.BeginVertical();
|
||||
if(GUILayout.Button("Restart Game", GUILayout.Width(150), GUILayout.Height(30))){
|
||||
Time.timeScale = 1;
|
||||
Application.LoadLevel(0);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space (90);
|
||||
GUI.color = Color(0, 20, 0, 0.6);
|
||||
if(!finishedGame){
|
||||
//GUILayout.Label("Objective: Find secret room using less time");
|
||||
GUILayout.Label(objective);
|
||||
}else{
|
||||
GUILayout.Label("Objective: Completed with time: " + niceTime + " min");
|
||||
}
|
||||
GUILayout.Space (5);
|
||||
GUI.color = Color.white;
|
||||
scroll3 = GUILayout.BeginScrollView(scroll3, GUILayout.Width(480), GUILayout.Height(115));
|
||||
GUI.color = Color(20, 20,0, 0.6);
|
||||
GUILayout.Label("Tab - Main Menu");
|
||||
GUILayout.Label("Q - slow motion");
|
||||
GUILayout.Label("P - Fullscreen");
|
||||
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");
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
function Resolutions(windowID : int){
|
||||
GUI.BringWindowToFront(windowID);
|
||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(140), GUILayout.Height(75));
|
||||
GUILayout.BeginVertical();
|
||||
for(var a : int; a < resolutions.Length; a++){
|
||||
if(resolutions[a].width == Screen.width && resolutions[a].height == Screen.height){
|
||||
GUI.color = Color(0, 20, 20, 0.6);
|
||||
}else{
|
||||
GUI.color = Color(20, 20, 20, 0.6);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
function QualityWindow(windowID : int){
|
||||
GUI.BringWindowToFront(windowID);
|
||||
scroll2 = GUILayout.BeginScrollView(scroll2, GUILayout.Width(140), GUILayout.Height(75));
|
||||
GUILayout.BeginVertical();
|
||||
for (var i = 0; i < QualityNames.Length; i++){
|
||||
if(QualityNames[i] == QualityNames[QualitySettings.GetQualityLevel ()]){
|
||||
GUI.color = Color(0, 20, 20, 0.6);
|
||||
}else{
|
||||
GUI.color = Color(20, 20, 20, 0.6);
|
||||
}
|
||||
if (GUILayout.Button (QualityNames[i]))
|
||||
QualitySettings.SetQualityLevel (i, true);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
function Pause(){
|
||||
if(mainMenu){
|
||||
Time.timeScale = 0.0001;
|
||||
Screen.lockCursor = false;
|
||||
}else{
|
||||
Time.timeScale = 1;
|
||||
Screen.lockCursor = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e1d6e920c6be1d41b60a009c430f70a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,49 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
var slowMotion : boolean;
|
||||
//How much should we slow time
|
||||
//Recomended values from 0.2 to 0.9
|
||||
var guiSkin : GUISkin;
|
||||
var slowTimeTo : float = 0.5;
|
||||
|
||||
@HideInInspector
|
||||
var audios : AudioSource[];
|
||||
|
||||
function Start () {
|
||||
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if(Time.timeScale < 0.01)
|
||||
return;
|
||||
|
||||
if(Input.GetKeyDown(KeyCode.Q)){
|
||||
slowMotion = !slowMotion;
|
||||
}
|
||||
|
||||
if(slowMotion){
|
||||
audios = FindObjectsOfType(AudioSource) as AudioSource[];
|
||||
for (var i = 0; i < audios.Length; i++){
|
||||
audios[i].pitch = slowTimeTo;
|
||||
}
|
||||
Time.timeScale = slowTimeTo;
|
||||
Time.fixedDeltaTime = 0.005;
|
||||
}
|
||||
else if(!slowMotion && Time.deltaTime != 1){
|
||||
audios = FindObjectsOfType(AudioSource) as AudioSource[];
|
||||
for (var a = 0; a < audios.Length; a++){
|
||||
audios[a].pitch = 1;
|
||||
}
|
||||
Time.timeScale = 1;
|
||||
Time.fixedDeltaTime = 0.02;
|
||||
}
|
||||
}
|
||||
|
||||
function OnGUI(){
|
||||
GUI.skin = guiSkin;
|
||||
GUI.color.a = 0.8;
|
||||
GUI.Box(Rect(Screen.width-205, 60, 200, 30), "Slow Mo: " + slowMotion.ToString());
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70f41bcd87b209b4b922cc992145b9e6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,49 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
var guiStyle : GUISkin;
|
||||
var weaps : GameObject;
|
||||
var teleportPoint : Transform;
|
||||
var mm : MainMenu;
|
||||
|
||||
private var inside : boolean;
|
||||
|
||||
function OnTriggerEnter(weapon : Collider){
|
||||
//Detect if we on pickable weapon
|
||||
if(weapon.gameObject.tag == "Player"){
|
||||
inside = true;
|
||||
}
|
||||
}
|
||||
|
||||
function OnTriggerExit(weapon : Collider){
|
||||
if(weapon.gameObject.tag == "Player"){
|
||||
inside = false;
|
||||
}
|
||||
}
|
||||
|
||||
function Update(){
|
||||
if(inside){
|
||||
if(Input.GetKeyDown(KeyCode.F)){
|
||||
GameObject.FindWithTag("Player").transform.position = teleportPoint.position;
|
||||
GameObject.FindWithTag("Player").transform.rotation = teleportPoint.rotation;
|
||||
inside = false;
|
||||
weaps.SetActiveRecursively(true);
|
||||
mm.finishedGame = true;
|
||||
RenderSettings.fog = false;
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function OnGUI(){
|
||||
if(!inside)
|
||||
return;
|
||||
GUI.skin = guiStyle;
|
||||
GUI.color.a = 0.9;
|
||||
GUI.depth = -10;
|
||||
var text : String = "Press ´F´ for MORE GUNS! ";
|
||||
var rect : Rect = Rect (Screen.width/2 - text.Length*9/2,Screen.height/2 - 25,text.Length*9,50);
|
||||
GUI.Box (rect, text);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81a0b172b1a8efd4c947788984213bfa
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72e14fd79e920514ba8f4589ab7f3353
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,32 @@
|
||||
//This script is used for next cases:
|
||||
//For example you pick RPG and shoot till last rocket
|
||||
//what this script do is deactivate rocked mesh, so it create and illusion
|
||||
//of having no ammo
|
||||
//Same for grenade and grenade launcher
|
||||
|
||||
import System.Collections.Generic;
|
||||
|
||||
#pragma strict
|
||||
|
||||
//Mesh that need to be deactivate while player have no ammo
|
||||
//For ex. Rocker, Grenade etc.
|
||||
var objectsToDeactivate : List.<GameObject>;
|
||||
//This need to be attached to the same object as WeaponScript
|
||||
private var weapScript : WeaponScript;
|
||||
|
||||
function Start () {
|
||||
weapScript = gameObject.GetComponent.<WeaponScript>();
|
||||
}
|
||||
|
||||
function Update () {
|
||||
//We make it work only with grenade launcher gun types
|
||||
if(weapScript.GunType == weapScript.gunType.GRENADE_LAUNCHER){
|
||||
for(var i = 0; i < objectsToDeactivate.Count; i++){
|
||||
if(weapScript.grenadeLauncher.ammoCount == 0){
|
||||
objectsToDeactivate[i].SetActiveRecursively(false);
|
||||
}else{
|
||||
objectsToDeactivate[i].SetActiveRecursively(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b5ab48befe92fa45b72780486a5d014
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,82 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
//@script ExecuteInEditMode
|
||||
var guiStyle : GUISkin;
|
||||
var display : boolean = true;
|
||||
private var bulletsLeft : int;
|
||||
private var clips : int;
|
||||
private var weaponscript : WeaponScript;
|
||||
private var weaponManager : WeaponManager;
|
||||
|
||||
private var currentWeapon : WeaponScript;
|
||||
private var color : float;
|
||||
|
||||
|
||||
function Awake () {
|
||||
weaponManager = gameObject.FindWithTag("WeaponManager").GetComponent.<WeaponManager>();
|
||||
}
|
||||
|
||||
function Update(){
|
||||
if(weaponManager.SelectedWeapon)
|
||||
weaponscript = weaponManager.SelectedWeapon.GetComponent.<WeaponScript>();
|
||||
if(!weaponscript)
|
||||
return;
|
||||
if(weaponscript.GunType == weaponscript.gunType.MACHINE_GUN){
|
||||
bulletsLeft = weaponscript.machineGun.bulletsLeft;
|
||||
clips = weaponscript.machineGun.clips;
|
||||
}
|
||||
|
||||
if(weaponscript.GunType == weaponscript.gunType.SHOTGUN){
|
||||
bulletsLeft = weaponscript.ShotGun.bulletsLeft;
|
||||
clips = weaponscript.ShotGun.clips;
|
||||
}
|
||||
|
||||
if(weaponscript.GunType == weaponscript.gunType.GRENADE_LAUNCHER){
|
||||
clips = weaponscript.grenadeLauncher.ammoCount;
|
||||
}
|
||||
|
||||
if(currentWeapon != weaponManager.SelectedWeapon){
|
||||
color = Mathf.Lerp(color, 0.3, Time.deltaTime*20);
|
||||
if(color < 0.32){
|
||||
currentWeapon = weaponManager.SelectedWeapon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function OnGUI (){
|
||||
if(!display)
|
||||
return;
|
||||
GUI.skin = guiStyle;
|
||||
GUI.color.a = 0.9;
|
||||
var rect : Rect = Rect (Screen.width - 110,Screen.height - 55,100,45);
|
||||
if(weaponscript){
|
||||
if(weaponscript.GunType != weaponscript.gunType.KNIFE){
|
||||
if(weaponscript.GunType == weaponscript.gunType.GRENADE_LAUNCHER){
|
||||
GUI.Box (rect, clips.ToString());
|
||||
}else{
|
||||
GUI.Box (rect, bulletsLeft + " | " + clips);
|
||||
}
|
||||
}else{
|
||||
GUI.Box (rect, "∞");
|
||||
}
|
||||
}
|
||||
|
||||
//SHow weapon list (Smoothly fade In/Out)
|
||||
if(weaponManager){
|
||||
GUILayout.BeginArea (Rect (0,0,Screen.width,30));
|
||||
GUILayout.BeginHorizontal();
|
||||
for(var i : int = 0; i < weaponManager.allWeapons.Count; i++){
|
||||
if(weaponManager.allWeapons[i] == currentWeapon && currentWeapon == weaponManager.SelectedWeapon ){
|
||||
color = Mathf.Lerp(color, 0.9, Time.deltaTime*20);
|
||||
GUI.color.a= color;
|
||||
}else{
|
||||
GUI.color.a = 0.3;
|
||||
}
|
||||
GUILayout.Box( weaponManager.allWeapons[i].weaponName, GUILayout.Height(30));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81264a45cd1c68f49a8471669debfe3d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,76 @@
|
||||
#pragma strict
|
||||
import System.Collections.Generic;
|
||||
|
||||
var speed : int = 500;
|
||||
var life : float = 3;
|
||||
var damage : int = 20;
|
||||
var impactForce : int = 10;
|
||||
var impactHoles : boolean = true;
|
||||
//Does bullet do any damage to target?
|
||||
var doDamage : boolean = false;
|
||||
//Impact prefab name corresponds a tag it should hit
|
||||
var impactObjects : List.<GameObject>;
|
||||
|
||||
|
||||
private var velocity : Vector3;
|
||||
private var newPos : Vector3;
|
||||
private var oldPos : Vector3;
|
||||
private var hasHit : boolean = false;
|
||||
|
||||
function Start () {
|
||||
newPos = transform.position;
|
||||
oldPos = newPos;
|
||||
velocity = speed * transform.forward;
|
||||
|
||||
// schedule for destruction if bullet never hits anything
|
||||
Destroy( gameObject, life );
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if( hasHit )
|
||||
return;
|
||||
// assume we move all the way
|
||||
newPos += velocity * Time.deltaTime;
|
||||
// Check if we hit anything on the way
|
||||
var direction : Vector3 = newPos - oldPos;
|
||||
var distance : float = direction.magnitude;
|
||||
|
||||
if (distance > 0) {
|
||||
var hit : RaycastHit;
|
||||
|
||||
if (Physics.Raycast(oldPos, direction, hit, distance)) {
|
||||
// adjust new position
|
||||
newPos = hit.point;
|
||||
// notify hit
|
||||
hasHit = true;
|
||||
var rotation : Quaternion = Quaternion.FromToRotation(Vector3.up, hit.normal);
|
||||
|
||||
//Apply force if we hit rigidbody
|
||||
if (hit.rigidbody){
|
||||
hit.rigidbody.AddForce( transform.forward * impactForce, ForceMode.Impulse );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////HIT SURFACES/////////////////////////////////////////////////////////////
|
||||
if(impactHoles){
|
||||
//var impact : GameObject;
|
||||
for(var i : int = 0; i<impactObjects.Count; i++){
|
||||
if(hit.transform.tag == impactObjects[i].name){
|
||||
Instantiate(impactObjects[i], hit.point, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//We cant hit ourselfs
|
||||
if(hit.transform.tag != "Player" && doDamage){
|
||||
hit.transform.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
Destroy (gameObject, 1);
|
||||
}
|
||||
}
|
||||
|
||||
oldPos = transform.position;
|
||||
transform.position = newPos;
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Weapon System/Bullet Controller")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d8c0cd52fd9c6041abe77da419b58d4
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,94 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
var walkBobbingSpeed = 0.21;
|
||||
var runBobbingSpeed = 0.35;
|
||||
var idleBobbingSpeed = 0.1;
|
||||
var bobbingAmount = 0.1;
|
||||
var smooth : float = 1;
|
||||
private var midpoint : Vector3;
|
||||
private var player : GameObject;
|
||||
private var timer = 0.0;
|
||||
private var bobbingSpeed : float;
|
||||
private var motor : FPScontroller;
|
||||
private var BobbingAmount : float;
|
||||
|
||||
function Awake (){
|
||||
//Find player and FPScontroller script
|
||||
player = GameObject.FindWithTag("Player");
|
||||
motor = player.GetComponent(FPScontroller);
|
||||
midpoint = transform.localPosition;
|
||||
|
||||
}
|
||||
|
||||
function FixedUpdate () {
|
||||
if(motor.prone)
|
||||
return;
|
||||
|
||||
//This variables is used for slow motion effect (0.02 should be default fixed time value)
|
||||
var tempWalkSpeed : float;
|
||||
var tempRunSpeed : float;
|
||||
var tempIdleSpeed : float;
|
||||
|
||||
if(Time.timeScale == 1){
|
||||
if(tempWalkSpeed != walkBobbingSpeed || tempRunSpeed != runBobbingSpeed || tempIdleSpeed != idleBobbingSpeed){
|
||||
tempWalkSpeed = walkBobbingSpeed;
|
||||
tempRunSpeed = runBobbingSpeed;
|
||||
tempIdleSpeed = idleBobbingSpeed;
|
||||
}
|
||||
}else{
|
||||
tempWalkSpeed = walkBobbingSpeed*(Time.fixedDeltaTime/0.02);
|
||||
tempRunSpeed = runBobbingSpeed*(Time.fixedDeltaTime/0.02);
|
||||
tempIdleSpeed = idleBobbingSpeed*(Time.fixedDeltaTime/0.02);
|
||||
}
|
||||
|
||||
var waveslice = 0.0;
|
||||
var waveslice2 = 0.0;
|
||||
var currentPosition : Vector3;
|
||||
waveslice = Mathf.Sin(timer*2);
|
||||
waveslice2 = Mathf.Sin(timer);
|
||||
timer = timer + bobbingSpeed;
|
||||
if (timer > Mathf.PI * 2) {
|
||||
timer = timer - (Mathf.PI * 2);
|
||||
}
|
||||
if (waveslice != 0) {
|
||||
var TranslateChange = waveslice * BobbingAmount;
|
||||
var TranslateChange2 = waveslice2 * BobbingAmount;
|
||||
var TotalAxes = Mathf.Clamp (1.0, 0.0, 1.0);
|
||||
var translateChange = TotalAxes * TranslateChange;
|
||||
var translateChange2 = TotalAxes * TranslateChange2;
|
||||
|
||||
if(motor.grounded){
|
||||
//Player walk
|
||||
currentPosition.y = midpoint.y + translateChange;
|
||||
currentPosition.x = midpoint.x + translateChange2;
|
||||
}
|
||||
|
||||
}else{
|
||||
//Player not move
|
||||
currentPosition = midpoint;
|
||||
}
|
||||
//Walk/Run sway speed
|
||||
if (motor.Walking && !motor.Running) {
|
||||
bobbingSpeed = tempWalkSpeed;
|
||||
BobbingAmount = bobbingAmount;
|
||||
}else if(motor.Running) {
|
||||
bobbingSpeed = tempRunSpeed;
|
||||
BobbingAmount = bobbingAmount;
|
||||
}
|
||||
|
||||
if(!motor.Running && !motor.Walking){
|
||||
bobbingSpeed = tempIdleSpeed;
|
||||
BobbingAmount = bobbingAmount*0.3;
|
||||
|
||||
}
|
||||
|
||||
var i : float;
|
||||
i += Time.deltaTime * smooth;
|
||||
|
||||
transform.localPosition = Vector3.Lerp(transform.localPosition, currentPosition, i);
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Character/FPS CameraBob")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 804c1a71096e57d45882bc8b5876027f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,46 @@
|
||||
var explosionRadius = 5.0;
|
||||
var explosionPower = 10.0;
|
||||
var explosionDamage = 100.0;
|
||||
var explosionTimeout = 2.0;
|
||||
var player1 = GameObject;
|
||||
|
||||
function Start () {
|
||||
|
||||
var explosionPosition = transform.position;
|
||||
|
||||
// Apply damage to close by objects first
|
||||
var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);
|
||||
for (var hit in colliders) {
|
||||
// Calculate distance from the explosion position to the closest point on the collider
|
||||
var closestPoint = hit.ClosestPointOnBounds(explosionPosition);
|
||||
var distance = Vector3.Distance(closestPoint, explosionPosition);
|
||||
|
||||
// The hit points we apply fall decrease with distance from the explosion point
|
||||
var hitPoints = 1.0 - Mathf.Clamp01(distance / explosionRadius);
|
||||
hitPoints *= explosionDamage;
|
||||
|
||||
// Tell the rigidbody or any other script attached to the hit object how much damage is to be applied!
|
||||
hit.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
// Apply explosion forzces to all rigidbodies
|
||||
// This needs to be in two steps for ragdolls to work correctly.
|
||||
// (Enemies are first turned into ragdolls with ApplyDamage then we apply forces to all the spawned body parts)
|
||||
colliders = Physics.OverlapSphere (explosionPosition, explosionRadius);
|
||||
for (var hit in colliders) {
|
||||
if (hit.rigidbody)
|
||||
hit.rigidbody.AddExplosionForce(explosionPower, explosionPosition, explosionRadius, 3.0);
|
||||
}
|
||||
|
||||
// stop emitting particles
|
||||
if (particleEmitter) {
|
||||
particleEmitter.emit = true;
|
||||
yield WaitForSeconds(0.5);
|
||||
particleEmitter.emit = false;
|
||||
}
|
||||
|
||||
Destroy (gameObject, explosionTimeout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22f010c99ff793248933718487b38f07
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,35 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
var turnOn : boolean;
|
||||
var flashLight : Light;
|
||||
var OnOffAudio : AudioClip;
|
||||
|
||||
function Start () {
|
||||
if(turnOn){
|
||||
flashLight.enabled = true;
|
||||
}else{
|
||||
flashLight.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function Update () {
|
||||
//Flash light input
|
||||
if(Input.GetKeyDown(KeyCode.G)){
|
||||
turnOn = !turnOn;
|
||||
flashLightOnOff();
|
||||
}
|
||||
}
|
||||
|
||||
function flashLightOnOff(){
|
||||
//Play flash light On/Off sound
|
||||
audio.clip = OnOffAudio;
|
||||
audio.Play();
|
||||
//Activate flash light
|
||||
if(turnOn){
|
||||
flashLight.enabled = true;
|
||||
}else{
|
||||
flashLight.enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe1069388685437478217174e66aa2d5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,57 @@
|
||||
// The reference to the explosion prefab
|
||||
var explosion : GameObject;
|
||||
var destroyDelay : float = 0;
|
||||
var timeOut = 3.0;
|
||||
var objectsToDestroy : GameObject[];
|
||||
|
||||
|
||||
var contact : ContactPoint;
|
||||
private var rotation : Quaternion;
|
||||
// Kill the rocket after a while automatically
|
||||
function Start () {
|
||||
if(destroyDelay > 0){
|
||||
Invoke("Kill", destroyDelay);
|
||||
}else{
|
||||
Invoke("Kill", timeOut);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function FixedUpdate(){
|
||||
//Make projectile to look on direction of his trajectory
|
||||
transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
|
||||
}
|
||||
|
||||
function OnCollisionEnter (collision : Collision) {
|
||||
// Instantiate explosion at the impact point and rotate the explosion
|
||||
// so that the y-axis faces along the surface normal
|
||||
contact = collision.contacts[0];
|
||||
rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
|
||||
|
||||
if(destroyDelay > 0)
|
||||
return;
|
||||
// And kill our selves
|
||||
Kill ();
|
||||
}
|
||||
|
||||
function Kill (){
|
||||
Instantiate (explosion, transform.position, rotation);
|
||||
// Stop emitting particles in any children
|
||||
var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
|
||||
if (emitter)
|
||||
emitter.emit = false;
|
||||
|
||||
// Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
|
||||
transform.DetachChildren();
|
||||
|
||||
// Destroy the projectile
|
||||
Destroy(gameObject);
|
||||
//Destroy some other objects that assigned to array (if needed)
|
||||
if(objectsToDestroy.Length > 0){
|
||||
for(var i = 0; i < objectsToDestroy.Length; i++){
|
||||
Destroy(objectsToDestroy[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@script RequireComponent (Rigidbody)
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e92823a42f2c44b528dd9d552a6bf756
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,69 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
//This script is used to control main weapon animations
|
||||
//Should be attached to the object that contain weapon/hand animation
|
||||
//Note this is Modifired version of WeaponAnimation.js and its adapted to work with per bullet reload animation
|
||||
var Idle : String = "Idle";
|
||||
var ReloadBegin : String = "Reload_1_3";
|
||||
var ReloadMiddle : String = "Reload_2_3";
|
||||
var ReloadEnd: String = "Reload_3_3";
|
||||
var Shoot : String = "Fire";
|
||||
var TakeIn : String = "TakeIn";
|
||||
var TakeOut : String = "TakeOut";
|
||||
var FireAnimationSpeed : float = 1;
|
||||
var TakeInOutSpeed : float = 1;
|
||||
var ReloadMiddleRepeat : float = 4;
|
||||
|
||||
private var PlayThis : String;
|
||||
|
||||
private var motor : FPScontroller;
|
||||
private var player : GameObject;
|
||||
|
||||
function Awake () {
|
||||
animation.Play(Idle);
|
||||
animation[Idle].wrapMode = WrapMode.Once;
|
||||
animation[ReloadBegin].wrapMode = WrapMode.Once;
|
||||
animation[ReloadMiddle].wrapMode = WrapMode.Once;
|
||||
animation[ReloadEnd].wrapMode = WrapMode.Once;
|
||||
animation[Shoot].wrapMode = WrapMode.Once;
|
||||
animation[TakeIn].wrapMode = WrapMode.Once;
|
||||
animation[TakeOut].wrapMode = WrapMode.Once;
|
||||
}
|
||||
|
||||
function Fire(){
|
||||
animation.Rewind(Shoot);
|
||||
animation[Shoot].speed = FireAnimationSpeed;
|
||||
animation.Play(Shoot);
|
||||
}
|
||||
|
||||
function Reloading(reloadTime : float) {
|
||||
var totalLength = animation[ReloadBegin].clip.length + animation[ReloadMiddle].clip.length*ReloadMiddleRepeat + animation[ReloadEnd].clip.length;
|
||||
|
||||
var newReload1 : AnimationState = animation.CrossFadeQueued(ReloadBegin);
|
||||
newReload1.speed = (totalLength/reloadTime)/2;
|
||||
//4 is number of bullets to reload
|
||||
for(var i : int = 0; i < ReloadMiddleRepeat; i++){
|
||||
var newReload2 : AnimationState = animation.CrossFadeQueued(ReloadMiddle);
|
||||
newReload2.speed = (totalLength/reloadTime)/1.4;
|
||||
}
|
||||
var newReload3 : AnimationState = animation.CrossFadeQueued(ReloadEnd);
|
||||
newReload3.speed = (totalLength/reloadTime)/2;
|
||||
}
|
||||
|
||||
function takeIn(){
|
||||
animation.Rewind(TakeIn);
|
||||
animation[TakeIn].speed = TakeInOutSpeed;
|
||||
animation[TakeIn].time = 0;
|
||||
animation.Play(TakeIn);
|
||||
}
|
||||
|
||||
function takeOut(){
|
||||
animation.Rewind(TakeOut);
|
||||
animation[TakeOut].speed = TakeInOutSpeed;
|
||||
animation[TakeOut].time = 0;
|
||||
animation.Play(TakeOut);
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Weapon System/SniperAnimation")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78f52baba798c474391f0502d5ec9df1
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,30 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
var scopeTexture : Texture2D;
|
||||
//When we aim, deactivate all visible Sniper parts (Hands, Gun etc.)
|
||||
var objectsToDeactivate : GameObject[];
|
||||
|
||||
private var weapScript : WeaponScript;
|
||||
|
||||
|
||||
function Awake () {
|
||||
weapScript = gameObject.GetComponent.<WeaponScript>();
|
||||
}
|
||||
|
||||
function OnGUI () {
|
||||
if(weapScript.aimed){
|
||||
GUI.DrawTexture(Rect(Screen.width/2- (Screen.height*1.8)/2,Screen.height/2-Screen.height/2, Screen.height*1.8, Screen.height), scopeTexture);
|
||||
for(var i : int = 0; i<objectsToDeactivate.Length;i++){
|
||||
objectsToDeactivate[i].SetActiveRecursively(false);
|
||||
}
|
||||
}else{
|
||||
for(var a : int = 0; a<objectsToDeactivate.Length;a++){
|
||||
objectsToDeactivate[a].SetActiveRecursively(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Weapon System/SniperScope")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9bc7fca7fedbd647b83db24d396dd01
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
var lifeTime = 2.0;
|
||||
|
||||
function Awake ()
|
||||
{
|
||||
Destroy (gameObject, lifeTime);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 796d0b47316e0cd4c8b9d8e20dbfafbb
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,103 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
//This script should be attached to an object whitch children are all player weapons
|
||||
//Weapon -> "Player weapons"
|
||||
|
||||
var walkBobbingSpeed = 0.21;
|
||||
var runBobbingSpeed = 0.35;
|
||||
var idleBobbingSpeed = 0.1;
|
||||
var bobbingAmount = 0.1;
|
||||
var smooth : float = 1;
|
||||
private var midpoint : Vector3;
|
||||
private var player : GameObject;
|
||||
private var timer = 0.0;
|
||||
private var bobbingSpeed : float;
|
||||
private var motor : FPScontroller;
|
||||
private var BobbingAmount : float;
|
||||
|
||||
function Awake (){
|
||||
//Find player and FPScontroller script
|
||||
player = GameObject.FindWithTag("Player");
|
||||
motor = player.GetComponent(FPScontroller);
|
||||
midpoint = transform.localPosition;
|
||||
|
||||
}
|
||||
|
||||
function FixedUpdate () {
|
||||
var waveslice = 0.0;
|
||||
var waveslice2 = 0.0;
|
||||
var currentPosition : Vector3;
|
||||
|
||||
//This variables is used for slow motion effect (0.02 should be default fixed time value)
|
||||
var tempWalkSpeed : float;
|
||||
var tempRunSpeed : float;
|
||||
var tempIdleSpeed : float;
|
||||
|
||||
if(Time.timeScale == 1){
|
||||
if(tempWalkSpeed != walkBobbingSpeed || tempRunSpeed != runBobbingSpeed || tempIdleSpeed != idleBobbingSpeed){
|
||||
tempWalkSpeed = walkBobbingSpeed;
|
||||
tempRunSpeed = runBobbingSpeed;
|
||||
tempIdleSpeed = idleBobbingSpeed;
|
||||
}
|
||||
}else{
|
||||
tempWalkSpeed = walkBobbingSpeed*(Time.fixedDeltaTime/0.02);
|
||||
tempRunSpeed = runBobbingSpeed*(Time.fixedDeltaTime/0.02);
|
||||
tempIdleSpeed = idleBobbingSpeed*(Time.fixedDeltaTime/0.02);
|
||||
}
|
||||
|
||||
/*
|
||||
if (!motor.Walking) {
|
||||
timer = 0.0;
|
||||
}else{
|
||||
*/
|
||||
waveslice = Mathf.Sin(timer*2);
|
||||
waveslice2 = Mathf.Sin(timer);
|
||||
timer = timer + bobbingSpeed;
|
||||
if (timer > Mathf.PI * 2) {
|
||||
timer = timer - (Mathf.PI * 2);
|
||||
}
|
||||
//}
|
||||
if (waveslice != 0) {
|
||||
var TranslateChange = waveslice * BobbingAmount;
|
||||
var TranslateChange2 = waveslice2 * BobbingAmount;
|
||||
var TotalAxes = Mathf.Clamp (1.0, 0.0, 1.0);
|
||||
var translateChange = TotalAxes * TranslateChange;
|
||||
var translateChange2 = TotalAxes * TranslateChange2;
|
||||
|
||||
if(motor.grounded){
|
||||
//Player walk
|
||||
currentPosition.y = midpoint.y + translateChange;
|
||||
currentPosition.x = midpoint.x + translateChange2;
|
||||
}
|
||||
|
||||
}else{
|
||||
//Player not move
|
||||
currentPosition = midpoint;
|
||||
}
|
||||
//Walk/Run sway speed
|
||||
if (motor.Walking && !motor.Running && !motor.prone) {
|
||||
bobbingSpeed = tempWalkSpeed;
|
||||
BobbingAmount = bobbingAmount;
|
||||
}
|
||||
if(motor.Running) {
|
||||
bobbingSpeed = tempRunSpeed;
|
||||
BobbingAmount = bobbingAmount;
|
||||
}
|
||||
|
||||
if(!motor.Running && !motor.Walking || motor.prone){
|
||||
bobbingSpeed = tempIdleSpeed;
|
||||
BobbingAmount = bobbingAmount*0.3;
|
||||
|
||||
}
|
||||
|
||||
var i : float;
|
||||
i += Time.deltaTime * smooth;
|
||||
|
||||
transform.localPosition = Vector3.Lerp(transform.localPosition, currentPosition, i);
|
||||
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Character/FPS WalkSway")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2254ab347885d544d87c84d1f32229dd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,52 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
//This script is used to control main weapon animations
|
||||
//Should be attached to the object that contain weapon/hand animation
|
||||
var Idle : String = "Idle";
|
||||
var Reload : String = "Reload";
|
||||
var Shoot : String = "Fire";
|
||||
var TakeIn : String = "TakeIn";
|
||||
var TakeOut : String = "TakeOut";
|
||||
var FireAnimationSpeed : float = 1;
|
||||
var TakeInOutSpeed : float = 1;
|
||||
|
||||
private var PlayThis : String;
|
||||
|
||||
private var motor : FPScontroller;
|
||||
private var player : GameObject;
|
||||
|
||||
function Awake () {
|
||||
animation.Play(Idle);
|
||||
animation.wrapMode = WrapMode.Once;
|
||||
}
|
||||
|
||||
function Fire(){
|
||||
animation.Rewind(Shoot);
|
||||
animation[Shoot].speed = FireAnimationSpeed;
|
||||
animation.Play(Shoot);
|
||||
}
|
||||
|
||||
function Reloading(reloadTime : float) {
|
||||
animation.Stop(Reload);
|
||||
animation[Reload].speed = (animation[Reload].clip.length/reloadTime);
|
||||
animation.Rewind(Reload);
|
||||
animation.Play(Reload);
|
||||
}
|
||||
|
||||
function takeIn(){
|
||||
animation.Rewind(TakeIn);
|
||||
animation[TakeIn].speed = TakeInOutSpeed;
|
||||
animation[TakeIn].time = 0;
|
||||
animation.Play(TakeIn);
|
||||
}
|
||||
|
||||
function takeOut(){
|
||||
animation.Rewind(TakeOut);
|
||||
animation[TakeOut].speed = TakeInOutSpeed;
|
||||
animation[TakeOut].time = 0;
|
||||
animation.Play(TakeOut);
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Weapon System/WeaponAnimation")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c972eb84cd80234abad43739c35e94f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,91 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
var crosshairTexture : Texture2D;
|
||||
var length : float = 15;
|
||||
var width : float =1;
|
||||
//Crosshair responce to player action
|
||||
var dynamicCrosshair : boolean = true;
|
||||
var crosshairResponce : float = 60;
|
||||
var defaultDistance : float = 40;
|
||||
var smooth : float = 0.3;
|
||||
private var crosshair : boolean = true;
|
||||
private var textu : Texture;
|
||||
private var lineStyle : GUIStyle;
|
||||
private var distance : float;
|
||||
private var currentDistance : float;
|
||||
private var motor : FPScontroller;
|
||||
private var weaponManager : WeaponManager;
|
||||
private var weaponScript : WeaponScript;
|
||||
|
||||
function Awake () {
|
||||
lineStyle = GUIStyle();
|
||||
lineStyle.normal.background = crosshairTexture;
|
||||
motor = gameObject.FindWithTag("Player").GetComponent.<FPScontroller>();
|
||||
weaponManager = gameObject.FindWithTag("WeaponManager").GetComponent.<WeaponManager>();
|
||||
}
|
||||
|
||||
function Update(){
|
||||
if(weaponManager){
|
||||
if(weaponManager.SelectedWeapon)
|
||||
weaponScript = weaponManager.SelectedWeapon.GetComponent.<WeaponScript>();
|
||||
}
|
||||
|
||||
if(Time.timeScale < 0.01)
|
||||
return;
|
||||
|
||||
if(dynamicCrosshair){
|
||||
var fireInput = Input.GetMouseButtonDown(0);
|
||||
//Dynamic crosshair***
|
||||
if(weaponScript && (fireInput || weaponScript.fire)){
|
||||
//Single weapons crosshair responce
|
||||
if(weaponScript.singleFire){
|
||||
if(fireInput && weaponScript.canFire && !weaponScript.isReload && !weaponScript.noBullets){
|
||||
if(distance < crosshairResponce*4){
|
||||
distance = distance + crosshairResponce;
|
||||
}
|
||||
}else{
|
||||
distance = Mathf.Lerp(distance, defaultDistance, Time.deltaTime/smooth);
|
||||
}
|
||||
}else{
|
||||
//Automatic weapons crosshair responce
|
||||
if(weaponScript.fire && !weaponScript.noBullets){
|
||||
currentDistance = crosshairResponce*2;
|
||||
}else{
|
||||
currentDistance = defaultDistance;
|
||||
}
|
||||
distance = Mathf.Lerp(distance, currentDistance, Time.deltaTime/smooth);
|
||||
}
|
||||
}else{
|
||||
if(motor.Walking){
|
||||
currentDistance = crosshairResponce+motor.movement.velocity.magnitude*2;
|
||||
}else{
|
||||
currentDistance = defaultDistance;
|
||||
}
|
||||
distance = Mathf.Lerp(distance, currentDistance, Time.deltaTime/smooth);
|
||||
}
|
||||
}else{
|
||||
distance = defaultDistance;
|
||||
}
|
||||
|
||||
if(weaponScript)
|
||||
if(weaponScript.aimed){
|
||||
crosshair = false;
|
||||
}else{
|
||||
crosshair = true;
|
||||
}
|
||||
}
|
||||
|
||||
function OnGUI () {
|
||||
if(!(distance > (Screen.height/2)) && crosshair){
|
||||
|
||||
GUI.Box(Rect((Screen.width - distance)/2 - length, (Screen.height - width)/2, length, width), textu, lineStyle);
|
||||
GUI.Box(Rect((Screen.width + distance)/2, (Screen.height- width)/2, length, width), textu, lineStyle);
|
||||
|
||||
GUI.Box(Rect((Screen.width - width)/2, (Screen.height - distance)/2 - length, width, length), textu, lineStyle);
|
||||
GUI.Box(Rect((Screen.width - width)/2, (Screen.height + distance)/2, width, length), textu, lineStyle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f58739f95156d4a4989511e6ad2cd82d
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,90 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
import System.Collections.Generic;
|
||||
//This script should be attached to an object called Weapons (Which children are all player weapons)
|
||||
//Weapons->Weapon1, Weapon2, Weapon3 etc.
|
||||
|
||||
var allWeapons : List.<WeaponScript>;
|
||||
var SwitchTime = 0.5;
|
||||
@HideInInspector
|
||||
public var SelectedWeapon : WeaponScript;
|
||||
//Weapon index (What weapon we should take in the beginning of game)
|
||||
//By default its 0 - take first weapon
|
||||
var index : int = 0;
|
||||
var takeInAudio : AudioClip;
|
||||
|
||||
private var defaultPrimaryWeap : GameObject;
|
||||
private var defaultSecondaryWeap : GameObject;
|
||||
|
||||
private var canSwitch : boolean;
|
||||
|
||||
function Awake(){
|
||||
for(var a : int = 0; a < transform.childCount;a++){
|
||||
transform.GetChild(a).gameObject.SetActiveRecursively(false);
|
||||
}
|
||||
for(var i : int; i < allWeapons.Count; i++){
|
||||
allWeapons[i].gameObject.SetActiveRecursively(false);
|
||||
}
|
||||
TakeFirstWeapon(allWeapons[index].gameObject);
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if(Time.timeScale < 0.01)
|
||||
return;
|
||||
|
||||
SelectedWeapon = allWeapons[index];
|
||||
if(allWeapons.Count < 2)
|
||||
return;
|
||||
//Switch to next weapon
|
||||
if(Input.GetKeyDown("2") && canSwitch){
|
||||
if(index < allWeapons.Count-1){
|
||||
SwitchWeapons(allWeapons[index].gameObject, allWeapons[index+1].gameObject);
|
||||
index++;
|
||||
}else{
|
||||
SwitchWeapons(allWeapons[allWeapons.Count-1].gameObject, allWeapons[0].gameObject);
|
||||
index=0;
|
||||
}
|
||||
}
|
||||
|
||||
//Switch to previous weapon
|
||||
if(Input.GetKeyDown("1") && canSwitch){
|
||||
if(index > 0){
|
||||
SwitchWeapons(allWeapons[index].gameObject, allWeapons[index-1].gameObject);
|
||||
index--;
|
||||
}else{
|
||||
SwitchWeapons(allWeapons[0].gameObject, allWeapons[allWeapons.Count-1].gameObject);
|
||||
index=allWeapons.Count-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function TakeFirstWeapon(nextWeapon : GameObject){
|
||||
//Play take audio
|
||||
audio.clip = takeInAudio;
|
||||
audio.Play();
|
||||
|
||||
nextWeapon.SetActiveRecursively(true);
|
||||
nextWeapon.SendMessage("selectWeapon");
|
||||
canSwitch = true;
|
||||
}
|
||||
|
||||
function SwitchWeapons(currentWeapon : GameObject, nextWeapon : GameObject){
|
||||
canSwitch = false;
|
||||
if(currentWeapon.active == true){
|
||||
currentWeapon.SendMessage("deselectWeapon");
|
||||
}
|
||||
yield WaitForSeconds(SwitchTime );
|
||||
//Play take audio
|
||||
audio.clip = takeInAudio;
|
||||
audio.Play();
|
||||
|
||||
currentWeapon.SetActiveRecursively(false);
|
||||
nextWeapon.SetActiveRecursively(true);
|
||||
nextWeapon.SendMessage("selectWeapon");
|
||||
canSwitch = true;
|
||||
}
|
||||
|
||||
@script RequireComponent (AudioSource)
|
||||
@script AddComponentMenu ("FPS system/Weapon System/WeaponManager")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7443215b51fe8dd4d91237d84c9f56cc
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,196 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
|
||||
import System.Collections.Generic;
|
||||
//This script is used to pick up available weapons
|
||||
//SHould be attached to GameObject with CharacterCOntroller component
|
||||
var guiStyle : GUISkin;
|
||||
|
||||
enum PickUpStyle {Replace, Add};
|
||||
var pickUpStyle : PickUpStyle;
|
||||
//When player pick weapon he have alredy add (BulletsPerClip*pickAmmoMultiply) amount of bullets
|
||||
var pickAmmoMultiply : int = 1;
|
||||
//If wepon have more then (BulletsPerClip*reserveAmmoLimit) bullets, dont auto pick it
|
||||
var reserveAmmoLimit : int = 3;
|
||||
var throwForce : float = 500;
|
||||
var spawnObject : Transform;
|
||||
//Display actions properties
|
||||
private var actionsToDisplay : int = 5;
|
||||
private var messageTimeOut : float = 5;
|
||||
|
||||
//Wepon models to throw
|
||||
var weapons : List.<GameObject>;
|
||||
//All available weapons (assign all existing weapons)
|
||||
var playerWeapons : List.<WeaponScript>;
|
||||
//Player actions ti be displayed
|
||||
@HideInInspector
|
||||
var actionsList : List.<String>;
|
||||
@HideInInspector
|
||||
var timer : List.<float>;
|
||||
|
||||
private var weapName : String;
|
||||
private var weaponToThrow : GameObject;
|
||||
private var newWeapon : WeaponScript;
|
||||
private var WeaponToPick : GameObject;
|
||||
private var weapManager : WeaponManager;
|
||||
//GUI Color fade
|
||||
private var color: float;
|
||||
private var text : String;
|
||||
|
||||
private var controller : CharacterController;
|
||||
private var prevHeight : float;
|
||||
|
||||
function Awake () {
|
||||
weapManager = gameObject.FindWithTag("WeaponManager").GetComponent.<WeaponManager>();
|
||||
controller = GetComponent (CharacterController);
|
||||
prevHeight = controller.height;
|
||||
}
|
||||
|
||||
function Update () {
|
||||
//Update weapon to pick status, incase trigger miss somthing
|
||||
if(prevHeight != controller.height){
|
||||
WeaponToPick = null;
|
||||
prevHeight = controller.height;
|
||||
}
|
||||
if(WeaponToPick){
|
||||
for(var a : int = 0; a < playerWeapons.Count; a++){
|
||||
if(playerWeapons[a].weaponName == WeaponToPick.name){
|
||||
newWeapon = playerWeapons[a];
|
||||
}
|
||||
}
|
||||
|
||||
for(var i : int = 0; i<weapons.Count;i++){
|
||||
if(weapons[i].name == weapManager.SelectedWeapon.weaponName){
|
||||
weaponToThrow = weapons[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(weapManager.allWeapons.Contains(newWeapon)){
|
||||
if(newWeapon.GunType == newWeapon.GunType.MACHINE_GUN){
|
||||
if(newWeapon.machineGun.clips < newWeapon.machineGun.bulletsPerClip*reserveAmmoLimit){
|
||||
newWeapon.machineGun.clips += newWeapon.machineGun.bulletsPerClip*pickAmmoMultiply;
|
||||
Destroy(WeaponToPick);
|
||||
//Register Action
|
||||
actionsList.Add(("Picked ammo for | " + newWeapon.weaponName).ToString());
|
||||
timer.Add(messageTimeOut);
|
||||
}else{
|
||||
text = "Full Ammo ";
|
||||
}
|
||||
}
|
||||
if(newWeapon.GunType == newWeapon.GunType.GRENADE_LAUNCHER){
|
||||
if(newWeapon.grenadeLauncher.ammoCount < reserveAmmoLimit){
|
||||
newWeapon.grenadeLauncher.ammoCount += pickAmmoMultiply;
|
||||
Destroy(WeaponToPick);
|
||||
//Register Action
|
||||
actionsList.Add(("Picked ammo for | " + newWeapon.weaponName).ToString());
|
||||
timer.Add(messageTimeOut);
|
||||
}else{
|
||||
text = "Full Ammo ";
|
||||
}
|
||||
}
|
||||
if(newWeapon.GunType == newWeapon.GunType.SHOTGUN){
|
||||
if(newWeapon.ShotGun.clips < newWeapon.ShotGun.bulletsPerClip * reserveAmmoLimit){
|
||||
newWeapon.ShotGun.clips += newWeapon.ShotGun.bulletsPerClip*pickAmmoMultiply;
|
||||
Destroy(WeaponToPick);
|
||||
//Register Action
|
||||
actionsList.Add(("Picked ammo for | " + newWeapon.weaponName).ToString());
|
||||
timer.Add(messageTimeOut);
|
||||
}else{
|
||||
text = "Full Ammo ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Press F key to pick up weapon
|
||||
if(Input.GetKeyDown(KeyCode.F)){
|
||||
if(pickUpStyle == PickUpStyle.Replace){
|
||||
if(weapManager.allWeapons.Contains(newWeapon))
|
||||
return;
|
||||
//Throw current weapon
|
||||
var clone : GameObject;
|
||||
clone = Instantiate(weaponToThrow, spawnObject.position, spawnObject.rotation);
|
||||
clone.name = weaponToThrow.name;
|
||||
//Add force when we throw weapon
|
||||
clone.rigidbody.AddForce (-spawnObject.transform.up * throwForce);
|
||||
weapManager.SwitchWeapons(weapManager.allWeapons[weapManager.index].gameObject, newWeapon.gameObject);
|
||||
weapManager.allWeapons[weapManager.index] = newWeapon;
|
||||
Destroy(WeaponToPick);
|
||||
//Register Action
|
||||
actionsList.Add(("Picked | " + newWeapon.weaponName).ToString());
|
||||
timer.Add(messageTimeOut);
|
||||
}
|
||||
if(pickUpStyle == PickUpStyle.Add){
|
||||
if(weapManager.allWeapons.Contains(newWeapon))
|
||||
return;
|
||||
weapManager.allWeapons.Add(newWeapon);
|
||||
weapManager.SwitchWeapons(weapManager.SelectedWeapon.gameObject, weapManager.allWeapons[weapManager.allWeapons.Count-1].gameObject);
|
||||
weapManager.index = weapManager.allWeapons.Count-1;
|
||||
Destroy(WeaponToPick);
|
||||
//Register Action
|
||||
actionsList.Add(("Picked | " + newWeapon.weaponName).ToString());
|
||||
timer.Add(messageTimeOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Remove actions
|
||||
if(timer.Count > 0){
|
||||
for(var b : int = 0; b < timer.Count; b ++){
|
||||
timer[b]-= Time.deltaTime;
|
||||
if(timer[b]<0){
|
||||
timer.Remove(timer[b]);
|
||||
actionsList.Remove(actionsList[b]);
|
||||
}
|
||||
}
|
||||
|
||||
if(timer.Count > actionsToDisplay && actionsList.Count > actionsToDisplay){
|
||||
timer.Remove(timer[0]);
|
||||
actionsList.Remove(actionsList[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function OnTriggerStay(weapon : Collider){
|
||||
//Detect if we on pickable weapon
|
||||
if(weapon.gameObject.tag == "PickUp"){
|
||||
WeaponToPick = weapon.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
function OnTriggerExit(weapon : Collider){
|
||||
if(weapon.gameObject.tag == "PickUp"){
|
||||
WeaponToPick = null;
|
||||
}
|
||||
}
|
||||
|
||||
function OnGUI(){
|
||||
GUI.skin = guiStyle;
|
||||
if(WeaponToPick){
|
||||
weapName = WeaponToPick.name;
|
||||
color = Mathf.Lerp(color, 0.9, Time.deltaTime*10);
|
||||
}else{
|
||||
color = Mathf.Lerp(color, 0, Time.deltaTime*10);
|
||||
}
|
||||
|
||||
GUI.color.a = color;
|
||||
|
||||
if(!weapManager.allWeapons.Contains(newWeapon)){
|
||||
text = "Press `F` to pick | " + weapName;
|
||||
}
|
||||
var rect : Rect = Rect (Screen.width/2 - text.Length*10/2,Screen.height - 105,text.Length*10,45);
|
||||
GUI.Box (rect, text );
|
||||
|
||||
GUI.color.a = 0.6;
|
||||
//Display actions
|
||||
GUILayout.BeginArea(Rect (10,Screen.height - (actionsList.Count*33)-10, 300 ,Screen.height));
|
||||
GUILayout.BeginVertical();
|
||||
for(var i : int = 0; i < actionsList.Count; i++){
|
||||
GUILayout.Box(actionsList[i], GUILayout.Width(300), GUILayout.Height(30));
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
@script AddComponentMenu ("FPS system/Weapon System/WeaponPickUp")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c76f1aebee513b044a83decc0195a109
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,802 @@
|
||||
//NSdesignGames @ 2012
|
||||
//FPS Kit | Version 2.0
|
||||
|
||||
#pragma strict
|
||||
#pragma implicit
|
||||
#pragma downcast
|
||||
|
||||
@System.Serializable
|
||||
|
||||
public class WeaponScript extends MonoBehaviour {
|
||||
//Booleans
|
||||
@HideInInspector
|
||||
var aimed : boolean;
|
||||
@HideInInspector
|
||||
var fire : boolean;
|
||||
@HideInInspector
|
||||
var canAim : boolean;
|
||||
@HideInInspector
|
||||
var isReload : boolean;
|
||||
@HideInInspector
|
||||
var noBullets : boolean;
|
||||
@HideInInspector
|
||||
var Recoil : boolean;
|
||||
@HideInInspector
|
||||
var canFire : boolean;
|
||||
@HideInInspector
|
||||
var singleFire : boolean;
|
||||
|
||||
private var motor : FPScontroller;
|
||||
private var player : GameObject;
|
||||
private var controller : CharacterController;
|
||||
private var mouseLook : FPSMouseLook;
|
||||
|
||||
//make walk sway amount smaller when player is aim
|
||||
//or aim mode walk sway control
|
||||
private var walkSway : WalkSway;
|
||||
private var defaultBobbingAmount : float;
|
||||
private var managerObject : GameObject;
|
||||
|
||||
enum gunType {MACHINE_GUN, GRENADE_LAUNCHER, SHOTGUN, KNIFE}
|
||||
var GunType : gunType;
|
||||
var FlashLight : boolean;
|
||||
|
||||
//Use classes to make a group of variables
|
||||
|
||||
var weaponName : String = "";
|
||||
|
||||
//Aim variables
|
||||
class AimVariables {
|
||||
var aimPosition : Vector3 = Vector3.zero;
|
||||
var smoothTime : float = 5;
|
||||
var toFov : float = 45;
|
||||
var aimBobbingAmount : float;
|
||||
var playAnimation : boolean;
|
||||
}
|
||||
var Aim : AimVariables;
|
||||
private var defaultFov : float;
|
||||
private var defaultPosition : Vector3;
|
||||
private var currentFov : float;
|
||||
private var currentPosition : Vector3;
|
||||
|
||||
var firePoint : Transform;
|
||||
|
||||
//Shotgun variables
|
||||
class shotGun{
|
||||
var bullet : Transform;
|
||||
var fractions : int = 5;
|
||||
var errorAngle : float = 3;
|
||||
var fireRate : float = 1;
|
||||
var reloadTime : float = 2;
|
||||
var fireSound : AudioClip;
|
||||
var reloadSound : AudioClip;
|
||||
var bulletsPerClip : int = 40;
|
||||
var bulletsLeft : int;
|
||||
var clips : int = 15;
|
||||
var smoke : ParticleEmitter;
|
||||
}
|
||||
var ShotGun : shotGun;
|
||||
|
||||
//Grenade launcher variables
|
||||
class GrenadeLauncher{
|
||||
var projectile : Rigidbody;
|
||||
var fireSound : AudioClip;
|
||||
var reloadSound : AudioClip;
|
||||
var initialSpeed = 20.0;
|
||||
//Delay shot (ex. greande throw)
|
||||
var shotDelay : float = 0;
|
||||
var waitBeforeReload = 0.5;
|
||||
var reloadTime = 0.5;
|
||||
var ammoCount = 20;
|
||||
}
|
||||
var grenadeLauncher : GrenadeLauncher;
|
||||
|
||||
private var lastShot = -10.0;
|
||||
|
||||
//Machine gun variables
|
||||
class MachineGun{
|
||||
var bullet : Transform;
|
||||
var muzzleFlash : GameObject;
|
||||
var fireSound : AudioClip;
|
||||
var reloadSound : AudioClip;
|
||||
var pointLight : Light;
|
||||
var fireRate = 0.05;
|
||||
var bulletsPerClip : int = 40;
|
||||
var clips : int = 15;
|
||||
var bulletsLeft : int;
|
||||
var reloadTime = 1.0;
|
||||
var NoAimErrorAngle = 3.0;
|
||||
var AimErrorAngle = 0.0;
|
||||
}
|
||||
var machineGun : MachineGun;
|
||||
@HideInInspector
|
||||
var errorAngle : float;
|
||||
private var nextFireTime = 0.0;
|
||||
|
||||
//Knife variables
|
||||
class Knife{
|
||||
var bullet : Transform;
|
||||
var fireSound : AudioClip;
|
||||
var fireRate : float = 0.5;
|
||||
var delayTime : float = 0;
|
||||
}
|
||||
var knife : Knife;
|
||||
|
||||
//Rotation realisn variables
|
||||
class RotationReal{
|
||||
var RotationAmplitude : float = 2;
|
||||
var smooth : float = 7;
|
||||
}
|
||||
var RotRealism : RotationReal;
|
||||
private var currentAnglex : float;
|
||||
private var currentAngley : float;
|
||||
|
||||
//Smooth move variables
|
||||
class SmoothMov {
|
||||
var maxAmount = 0.5;
|
||||
var Smooth = 3.0;
|
||||
}
|
||||
var SmoothMovement : SmoothMov;
|
||||
private var DefaultPos : Vector3;
|
||||
|
||||
//Camera Recoil effect NOTE : Be sure that is your player camera is tagged as "MainCamera"
|
||||
class cameraRecoil{
|
||||
var recoilPower : float = 0.5;
|
||||
var shakeAmount : float = 6;
|
||||
var smooth : float = 3;
|
||||
}
|
||||
var CameraRecoil : cameraRecoil;
|
||||
private var camDefaultRotation : Quaternion;
|
||||
private var camPos : Quaternion;
|
||||
|
||||
//Awake function is always called before Start function
|
||||
function Awake(){
|
||||
//Find nesessary objects and scripts (Player, CharacterMotor script, and weapon projectile spawn points etc.)
|
||||
player = GameObject.FindWithTag("Player");
|
||||
motor = player.GetComponent(FPScontroller);
|
||||
controller = player.GetComponent(CharacterController);
|
||||
mouseLook = gameObject.FindWithTag("LookObject").GetComponent("FPSMouseLook");
|
||||
}
|
||||
|
||||
function Start (){
|
||||
//Aim mode walk sway control
|
||||
managerObject = gameObject.FindWithTag("WeaponManager");
|
||||
walkSway = managerObject.GetComponent("WalkSway");
|
||||
defaultBobbingAmount = walkSway.bobbingAmount;
|
||||
|
||||
//Camera recoil
|
||||
camDefaultRotation = camera.main.transform.localRotation;
|
||||
|
||||
//Aim setup
|
||||
defaultFov = camera.main.fieldOfView;
|
||||
defaultPosition = transform.localPosition;
|
||||
|
||||
//Call machineGun awake
|
||||
if(GunType == gunType.MACHINE_GUN){
|
||||
machineGunAwake();
|
||||
}
|
||||
//Call grenadelauncher awake
|
||||
if(GunType == gunType.GRENADE_LAUNCHER){
|
||||
grenadeLauncherAwake();
|
||||
}
|
||||
|
||||
//Call shotgun Awake
|
||||
if(GunType == gunType.SHOTGUN){
|
||||
shotGunAwake();
|
||||
}
|
||||
|
||||
//Call knife awake
|
||||
if(GunType == gunType.KNIFE){
|
||||
knifeAwake();
|
||||
}
|
||||
}
|
||||
|
||||
function Update (){
|
||||
if(Time.timeScale < 0.01)
|
||||
return;
|
||||
Aiming();
|
||||
RotationRealism();
|
||||
SmoothMove();
|
||||
//PickUpUpdate();
|
||||
//input();
|
||||
if(Recoil){
|
||||
cameraRecoilDo();
|
||||
}
|
||||
//Call machine gun fixed update function
|
||||
if(GunType == gunType.MACHINE_GUN){
|
||||
machineGunFixedUpdate();
|
||||
}
|
||||
//Call grenade launcher fixed update function
|
||||
if(GunType == gunType.GRENADE_LAUNCHER){
|
||||
grenadeLauncherFixedUpdate();
|
||||
}
|
||||
|
||||
//Call shotgun fixed update function
|
||||
if(GunType == gunType.SHOTGUN){
|
||||
shotGunFixedUpdate ();
|
||||
}
|
||||
if(motor.Running){
|
||||
aimed = false;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////INPUT//////////////////////////////////////////////////////////////////////
|
||||
function LateUpdate(){
|
||||
if(Time.timeScale < 0.01)
|
||||
return;
|
||||
//1.Aim input
|
||||
if(Input.GetButtonDown("Fire2") && canAim && !motor.Running){
|
||||
aimed = !aimed;
|
||||
}
|
||||
//2.Fire input
|
||||
//Automatic fire input
|
||||
if(Input.GetButton("Fire1") && canFire && !singleFire){
|
||||
fire = true;
|
||||
}else{
|
||||
fire = false;
|
||||
}
|
||||
//Single fire iputs
|
||||
if(GunType == gunType.MACHINE_GUN){
|
||||
//Single fire input for machine gun mode
|
||||
if(Input.GetButtonDown("Fire1") && canFire && !isReload && singleFire){
|
||||
machineGunFire();
|
||||
}else{
|
||||
machineGunStopFire ();
|
||||
}
|
||||
}
|
||||
|
||||
if(GunType == gunType.GRENADE_LAUNCHER){
|
||||
//Single fire input for grenade launcher mode
|
||||
if(Input.GetButtonDown("Fire1") && canFire && !isReload && singleFire){
|
||||
grenadeLauncherFIre();
|
||||
}
|
||||
}
|
||||
|
||||
if(GunType == gunType.SHOTGUN){
|
||||
//Single fire input for shotgun mode
|
||||
if(Input.GetButtonDown("Fire1") && canFire && !isReload && singleFire){
|
||||
shotGunFire ();
|
||||
}
|
||||
}
|
||||
|
||||
if(GunType == gunType.KNIFE){
|
||||
if(Input.GetButtonDown("Fire1") && canFire && !isReload && singleFire){
|
||||
knifeOneShot();
|
||||
}
|
||||
}
|
||||
|
||||
//3.Reload input
|
||||
if(Input.GetKeyDown("r") && !isReload && machineGun.clips > 0){
|
||||
if(GunType == gunType.MACHINE_GUN && machineGun.bulletsLeft != machineGun.bulletsPerClip){
|
||||
machineGunReload();
|
||||
}
|
||||
if(GunType == gunType.SHOTGUN && ShotGun.bulletsLeft != ShotGun.bulletsPerClip){
|
||||
shotGunReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function firePointSetup(){
|
||||
//Make fire point be directly to center of screen, to avoid out of crosshair fire bug
|
||||
var tempPos : Vector3 = Camera.main.ScreenToWorldPoint( Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane));
|
||||
firePoint.position = tempPos;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////MACHINE GUN FUNCTIONS///////////////////////////////////////////////////////
|
||||
function machineGunAwake(){
|
||||
machineGun.bulletsLeft = machineGun.bulletsPerClip;
|
||||
//Deactivate muzzleFlash if we didnt
|
||||
if(machineGun.muzzleFlash){
|
||||
machineGun.muzzleFlash.active = false;
|
||||
}
|
||||
canAim = true;
|
||||
canFire = true;
|
||||
}
|
||||
|
||||
function machineGunFixedUpdate (){
|
||||
//Machine gun fire
|
||||
if(fire && !isReload){
|
||||
machineGunFire();
|
||||
}else{
|
||||
machineGunStopFire();
|
||||
if(machineGun.muzzleFlash){
|
||||
machineGun.muzzleFlash.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(isReload){
|
||||
//motor.canRun = false;
|
||||
canAim = false;
|
||||
}
|
||||
}
|
||||
|
||||
function machineGunFire (){
|
||||
if (machineGun.bulletsLeft == 0)
|
||||
return;
|
||||
|
||||
// If there is more than one bullet between the last and this frame
|
||||
// Reset the nextFireTime
|
||||
if (Time.time - machineGun.fireRate > nextFireTime){
|
||||
nextFireTime = Time.time - Time.deltaTime;
|
||||
}
|
||||
// Keep firing until we used up the fire time
|
||||
while( nextFireTime < Time.time && machineGun.bulletsLeft != 0)
|
||||
{
|
||||
machineGunOneShot();
|
||||
nextFireTime += machineGun.fireRate;
|
||||
}
|
||||
//motor.canRun = false;
|
||||
|
||||
}
|
||||
|
||||
function machineGunStopFire (){
|
||||
motor.canRun = true;
|
||||
}
|
||||
|
||||
function machineGunOneShot () {
|
||||
if(!aimed){
|
||||
//Before fire, move aim point to right position
|
||||
firePointSetup();
|
||||
}
|
||||
var oldRotation = firePoint.rotation;
|
||||
firePoint.rotation = Quaternion.Euler(Random.insideUnitSphere * errorAngle) * transform.rotation;
|
||||
var instantiatedProjectile;
|
||||
if(!aimed){
|
||||
instantiatedProjectile = Instantiate (machineGun.bullet, firePoint.position, firePoint.rotation);
|
||||
}else{
|
||||
var pos : Vector3 = Camera.main.ScreenToWorldPoint( Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane));
|
||||
instantiatedProjectile = Instantiate (machineGun.bullet, pos, firePoint.rotation);
|
||||
}
|
||||
firePoint.rotation = oldRotation;
|
||||
lastShot = Time.time;
|
||||
machineGun.bulletsLeft--;
|
||||
//Play fire sound attached to a Weapon object
|
||||
audio.clip = machineGun.fireSound;
|
||||
audio.Play();
|
||||
//Do a light effect when shoot
|
||||
machineGunMuzzleFlash();
|
||||
//Send message to weapon animation script
|
||||
if(aimed && Aim.playAnimation){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(!aimed){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(Recoil){
|
||||
mouseLook.Recoil(CameraRecoil.recoilPower);
|
||||
machineGunCameraRecoil();
|
||||
}
|
||||
|
||||
// Reload gun in reload Time
|
||||
if(machineGun.clips > 0)
|
||||
if (machineGun.bulletsLeft == 0){
|
||||
noBullets = true;
|
||||
yield WaitForSeconds(1);
|
||||
if(!isReload){
|
||||
machineGunReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function machineGunMuzzleFlash(){
|
||||
|
||||
if(machineGun.muzzleFlash){
|
||||
machineGun.muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.Range(0, 359), Vector3.left);
|
||||
machineGun.muzzleFlash.active = true;
|
||||
}
|
||||
if(machineGun.pointLight){
|
||||
machineGun.pointLight.enabled = true;
|
||||
}
|
||||
yield WaitForSeconds(0.04);
|
||||
if(machineGun.muzzleFlash){
|
||||
machineGun.muzzleFlash.active = false;
|
||||
}
|
||||
if(machineGun.pointLight){
|
||||
machineGun.pointLight.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function machineGunReload () {
|
||||
isReload = true;
|
||||
aimed = false;
|
||||
canAim = false;
|
||||
BroadcastMessage ("Reloading", machineGun.reloadTime, SendMessageOptions.DontRequireReceiver);
|
||||
//Play reload sound
|
||||
audio.clip = machineGun.reloadSound;
|
||||
audio.Play();
|
||||
// Wait for reload time first - then add more bullets!
|
||||
yield WaitForSeconds(machineGun.reloadTime);
|
||||
|
||||
// We have a clip left reload
|
||||
if (machineGun.clips > 0)
|
||||
{
|
||||
var difference = machineGun.bulletsPerClip-machineGun.bulletsLeft;
|
||||
if(machineGun.clips > difference ){
|
||||
machineGun.clips = machineGun.clips - difference;
|
||||
machineGun.bulletsLeft = machineGun.bulletsLeft + difference;
|
||||
}else{
|
||||
machineGun.bulletsLeft = machineGun.bulletsLeft + machineGun.clips;
|
||||
machineGun.clips = 0;
|
||||
}
|
||||
noBullets = false;
|
||||
isReload = false;
|
||||
canAim = true;
|
||||
motor.canRun = true;
|
||||
}
|
||||
}
|
||||
|
||||
function machineGunCameraRecoil(){
|
||||
camPos = Quaternion.Euler (Random.Range(0, -CameraRecoil.shakeAmount), Random.Range(-CameraRecoil.shakeAmount, CameraRecoil.shakeAmount), 0);
|
||||
yield WaitForSeconds(0.05);
|
||||
camPos = camDefaultRotation;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////GRENADE LAUNCHER FUNCTIONS////////////////////////////////////////////
|
||||
function grenadeLauncherAwake(){
|
||||
canAim = true;
|
||||
canFire = true;
|
||||
}
|
||||
|
||||
function grenadeLauncherFixedUpdate (){
|
||||
//GrenadeLauncher fire
|
||||
if(fire && !isReload){
|
||||
grenadeLauncherFIre();
|
||||
//motor.canRun = false;
|
||||
}else{
|
||||
motor.canRun = true;
|
||||
}
|
||||
}
|
||||
|
||||
function grenadeLauncherFIre (){
|
||||
// Did the time exceed the reload time?
|
||||
if (grenadeLauncher.ammoCount == 0 || !canFire)
|
||||
return;
|
||||
|
||||
// If there is more than one bullet between the last and this frame
|
||||
// Reset the nextFireTime
|
||||
if (Time.time - grenadeLauncher.reloadTime > nextFireTime){
|
||||
nextFireTime = Time.time - Time.deltaTime;
|
||||
}
|
||||
// Keep firing until we used up the fire time
|
||||
while( nextFireTime < Time.time && grenadeLauncher.ammoCount > 0)
|
||||
{
|
||||
grenadeLauncherOneShot();
|
||||
nextFireTime += grenadeLauncher.reloadTime;
|
||||
}
|
||||
//motor.canRun = false;
|
||||
|
||||
}
|
||||
|
||||
function grenadeLauncherOneShot (){
|
||||
if(grenadeLauncher.shotDelay > 0){
|
||||
//Send message to weapon animation script
|
||||
if(aimed && Aim.playAnimation){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(!aimed){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(Recoil){
|
||||
mouseLook.Recoil(CameraRecoil.recoilPower);
|
||||
grenadeLauncherCameraRecoil();
|
||||
}
|
||||
grenadeLauncherReload();
|
||||
yield WaitForSeconds(grenadeLauncher.shotDelay);
|
||||
}
|
||||
// create a new projectile, use the same position and rotation as the Launcher.
|
||||
var instantiatedProjectile = Instantiate(grenadeLauncher.projectile, firePoint.position, firePoint.rotation);
|
||||
// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
|
||||
instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, grenadeLauncher.initialSpeed));
|
||||
|
||||
// Ignore collisions between the missile and the character controller
|
||||
var c : Collider;
|
||||
for(c in transform.root.GetComponentsInChildren(Collider))
|
||||
Physics.IgnoreCollision(instantiatedProjectile.collider, c);
|
||||
|
||||
lastShot = Time.time;
|
||||
grenadeLauncher.ammoCount--;
|
||||
audio.clip = grenadeLauncher.fireSound;
|
||||
audio.Play();
|
||||
if(grenadeLauncher.shotDelay == 0){
|
||||
//Send message to weapon animation script
|
||||
if(aimed && Aim.playAnimation){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(!aimed){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(Recoil){
|
||||
mouseLook.Recoil(CameraRecoil.recoilPower);
|
||||
grenadeLauncherCameraRecoil();
|
||||
}
|
||||
if(grenadeLauncher.ammoCount > 0){
|
||||
grenadeLauncherReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function grenadeLauncherReload(){
|
||||
isReload = true;
|
||||
yield WaitForSeconds(grenadeLauncher.waitBeforeReload);
|
||||
aimed = false;
|
||||
BroadcastMessage ("Reloading", grenadeLauncher.reloadTime, SendMessageOptions.DontRequireReceiver);
|
||||
//Play reload sound
|
||||
audio.clip = grenadeLauncher.reloadSound;
|
||||
audio.Play();
|
||||
yield WaitForSeconds(grenadeLauncher.reloadTime);
|
||||
isReload = false;
|
||||
}
|
||||
|
||||
function grenadeLauncherCameraRecoil(){
|
||||
camPos = Quaternion.Euler (Random.Range(-CameraRecoil.shakeAmount*1.5, -CameraRecoil.shakeAmount), Random.Range(CameraRecoil.shakeAmount/3, CameraRecoil.shakeAmount/2), 0);
|
||||
yield WaitForSeconds(0.1);
|
||||
camPos = camDefaultRotation;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////SHOTGUN FUNCTIONS/////////////////////////////////////////////////////////
|
||||
function shotGunAwake(){
|
||||
ShotGun.bulletsLeft = ShotGun.bulletsPerClip;
|
||||
if(ShotGun.smoke){
|
||||
ShotGun.smoke.emit = false;
|
||||
}
|
||||
canAim = true;
|
||||
canFire = true;
|
||||
}
|
||||
|
||||
function shotGunFixedUpdate (){
|
||||
if(fire && !isReload){
|
||||
shotGunFire();
|
||||
}else{
|
||||
shotGunStopFire();
|
||||
}
|
||||
|
||||
if(isReload){
|
||||
//motor.canRun = false;
|
||||
canAim = false;
|
||||
}
|
||||
}
|
||||
|
||||
function shotGunFire (){
|
||||
if (ShotGun.bulletsLeft == 0)
|
||||
return;
|
||||
|
||||
// If there is more than one bullet between the last and this frame
|
||||
// Reset the nextFireTime
|
||||
if (Time.time - ShotGun.fireRate > nextFireTime)
|
||||
nextFireTime = Time.time - Time.deltaTime;
|
||||
|
||||
// Keep firing until we used up the fire time
|
||||
while( nextFireTime < Time.time && ShotGun.bulletsLeft != 0)
|
||||
{
|
||||
shotGunOneShot();
|
||||
nextFireTime += ShotGun.fireRate;
|
||||
}
|
||||
//motor.canRun = false;
|
||||
}
|
||||
|
||||
function shotGunStopFire (){
|
||||
motor.canRun = true;
|
||||
}
|
||||
|
||||
function shotGunOneShot () {
|
||||
//Before fire, move aim point to right position
|
||||
firePointSetup();
|
||||
var oldRotation = firePoint.rotation;
|
||||
for (var i : int = 0;i < ShotGun.fractions; i++) {
|
||||
firePoint.rotation = Quaternion.Euler(Random.insideUnitSphere * ShotGun.errorAngle) * transform.rotation;
|
||||
var instantiatedProjectile = Instantiate (ShotGun.bullet, firePoint.position, firePoint.rotation);
|
||||
}
|
||||
firePoint.rotation = oldRotation;
|
||||
lastShot = Time.time;
|
||||
//Play fire sound attached to a Weapon object
|
||||
audio.clip = ShotGun.fireSound;
|
||||
audio.Play();
|
||||
ShotGun.bulletsLeft--;
|
||||
//Send message to weapon animation script
|
||||
if(aimed && Aim.playAnimation){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
if(!aimed){
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
shotGunSmokeEffect();
|
||||
if(Recoil){
|
||||
shotGunCameraRecoil();
|
||||
mouseLook.Recoil(CameraRecoil.recoilPower);
|
||||
}
|
||||
|
||||
// Reload gun in reload Time
|
||||
if(ShotGun.clips > 0)
|
||||
if (ShotGun.bulletsLeft == 0){
|
||||
noBullets = true;
|
||||
yield WaitForSeconds(1);
|
||||
if(!isReload){
|
||||
shotGunReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function shotGunReload () {
|
||||
isReload = true;
|
||||
aimed = false;
|
||||
BroadcastMessage ("Reloading", ShotGun.reloadTime, SendMessageOptions.DontRequireReceiver);
|
||||
//Play reload sound
|
||||
audio.clip = ShotGun.reloadSound;
|
||||
audio.Play();
|
||||
// Wait for reload time first - then add more bullets!
|
||||
yield WaitForSeconds(ShotGun.reloadTime);
|
||||
|
||||
// We have a clip left reload
|
||||
if (ShotGun.clips > 0){
|
||||
var difference = ShotGun.bulletsPerClip-ShotGun.bulletsLeft;
|
||||
if(ShotGun.clips > difference ){
|
||||
ShotGun.clips = ShotGun.clips - difference;
|
||||
ShotGun.bulletsLeft = ShotGun.bulletsLeft + difference;
|
||||
}else{
|
||||
ShotGun.bulletsLeft = ShotGun.bulletsLeft + ShotGun.clips;
|
||||
ShotGun.clips = 0;
|
||||
}
|
||||
noBullets = false;
|
||||
isReload = false;
|
||||
canAim = true;
|
||||
motor.canRun = true;
|
||||
}
|
||||
}
|
||||
|
||||
function shotGunSmokeEffect(){
|
||||
if(!ShotGun.smoke)
|
||||
return;
|
||||
ShotGun.smoke.emit = true;
|
||||
yield WaitForSeconds(0.3);
|
||||
ShotGun.smoke.emit = false;
|
||||
}
|
||||
|
||||
function shotGunCameraRecoil(){
|
||||
camPos = Quaternion.Euler (Random.Range(-CameraRecoil.shakeAmount*1.5, -CameraRecoil.shakeAmount), Random.Range(CameraRecoil.shakeAmount/3, CameraRecoil.shakeAmount/2), 0);
|
||||
yield WaitForSeconds(0.1);
|
||||
camPos = camDefaultRotation;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////KNIFE FUNCTIONS///////////////////////////////////
|
||||
function knifeAwake(){
|
||||
canAim = false;
|
||||
canFire = true;
|
||||
}
|
||||
|
||||
function knifeOneShot () {
|
||||
if (Time.time > knife.fireRate + lastShot){
|
||||
//Before fire, move aim point to right position
|
||||
firePointSetup();
|
||||
//Play fire sound attached to a Weapon object
|
||||
audio.clip = knife.fireSound;
|
||||
audio.Play();
|
||||
BroadcastMessage ("Fire", SendMessageOptions.DontRequireReceiver);
|
||||
|
||||
yield WaitForSeconds(knife.delayTime);
|
||||
|
||||
var instantiatedProjectile = Instantiate (knife.bullet, firePoint.position, firePoint.rotation);
|
||||
lastShot = Time.time;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////AIM FUNCTIONS////////////////////////////////////
|
||||
function Aiming(){
|
||||
//Change camera FOV and weapon transform to aim values
|
||||
if(aimed && !motor.Running){
|
||||
currentPosition = Aim.aimPosition;
|
||||
currentFov = Aim.toFov;
|
||||
errorAngle = machineGun.AimErrorAngle;
|
||||
walkSway.bobbingAmount = Aim.aimBobbingAmount;
|
||||
//mouseLook.sensitivityX = mouseLook.defaultSensitivityX/1.1;
|
||||
//mouseLook.sensitivityY = mouseLook.defaultSensitivityY/1.1;
|
||||
} else {
|
||||
currentPosition = defaultPosition;
|
||||
currentFov = defaultFov;
|
||||
errorAngle = machineGun.NoAimErrorAngle;
|
||||
walkSway.bobbingAmount = defaultBobbingAmount;
|
||||
//mouseLook.sensitivityX = mouseLook.defaultSensitivityX;
|
||||
//mouseLook.sensitivityY = mouseLook.defaultSensitivityY;
|
||||
}
|
||||
//Change weapon position and camera FOV when player aim or no aim
|
||||
transform.localPosition = Vector3.Lerp(transform.localPosition, currentPosition, Time.deltaTime/Aim.smoothTime);
|
||||
camera.main.fieldOfView = Mathf.Lerp(camera.main.fieldOfView, currentFov, Time.deltaTime/Aim.smoothTime);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
function cameraRecoilDo(){
|
||||
camera.main.transform.localRotation = Quaternion.Slerp(camera.main.transform.localRotation, camPos, Time.deltaTime * CameraRecoil.smooth);
|
||||
}
|
||||
|
||||
function RotationRealism (){
|
||||
//ROTATION REALISM
|
||||
var Xinput=Input.GetAxis("Mouse X");
|
||||
var Yinput=Input.GetAxis("Mouse Y");
|
||||
var currentAngley : float;
|
||||
var currentAnglex : float;
|
||||
|
||||
if(Mathf.Abs(Xinput)>0.1){
|
||||
if(Xinput < 0.1){
|
||||
//Left
|
||||
currentAngley = -RotRealism.RotationAmplitude * Mathf.Abs(Xinput);
|
||||
}
|
||||
else if(Xinput > 0.1){
|
||||
//Right;
|
||||
currentAngley = RotRealism.RotationAmplitude * Mathf.Abs(Xinput);
|
||||
}
|
||||
} else {
|
||||
//Center
|
||||
currentAngley = 0;
|
||||
}
|
||||
|
||||
if(Mathf.Abs(Yinput)>0.1){
|
||||
if(Yinput < 0.1){
|
||||
//Down
|
||||
currentAnglex = RotRealism.RotationAmplitude * Mathf.Abs(Yinput);
|
||||
}
|
||||
else if(Yinput > 0.1){
|
||||
//Up
|
||||
currentAnglex = -RotRealism.RotationAmplitude * Mathf.Abs(Yinput);
|
||||
}
|
||||
} else {
|
||||
//Center
|
||||
currentAnglex = 0;
|
||||
}
|
||||
|
||||
var target = Quaternion.Euler (currentAnglex, currentAngley, 0);
|
||||
transform.localRotation = Quaternion.Slerp(transform.localRotation, target, Time.deltaTime * RotRealism.smooth);
|
||||
}
|
||||
|
||||
function SmoothMove (){
|
||||
//var MoveOnX : float = -Input.GetAxis("Horizontal");
|
||||
var MoveOnY = controller.velocity.y;
|
||||
var m : float;
|
||||
var MoveOnZ : float = -Input.GetAxis("Vertical");
|
||||
/*
|
||||
if (MoveOnX > SmoothMovement.maxAmount)
|
||||
MoveOnX = SmoothMovement.maxAmount;
|
||||
|
||||
if (MoveOnX < -SmoothMovement.maxAmount)
|
||||
MoveOnX = -SmoothMovement.maxAmount;
|
||||
*/
|
||||
if(MoveOnY > SmoothMovement.maxAmount+1)
|
||||
m = -SmoothMovement.maxAmount;
|
||||
|
||||
if(MoveOnY < -SmoothMovement.maxAmount-1)
|
||||
m = SmoothMovement.maxAmount;
|
||||
|
||||
if (MoveOnZ> SmoothMovement.maxAmount)
|
||||
MoveOnZ = SmoothMovement.maxAmount;
|
||||
|
||||
if (MoveOnZ < -SmoothMovement.maxAmount)
|
||||
MoveOnZ = -SmoothMovement.maxAmount;
|
||||
|
||||
//var NewGunPos = new Vector3 (defaultPosition.x+ MoveOnX, defaultPosition.y + m, defaultPosition.z+ MoveOnZ);
|
||||
var NewGunPos = new Vector3 (transform.localPosition.x, transform.localPosition.y + m, transform.localPosition.z + MoveOnZ);
|
||||
transform.localPosition = Vector3.Lerp (transform.localPosition, NewGunPos, Time.deltaTime * SmoothMovement.Smooth);
|
||||
}
|
||||
|
||||
function selectWeapon(){
|
||||
canFire = true;
|
||||
if(GunType != gunType.KNIFE){
|
||||
canAim = true;
|
||||
}
|
||||
aimed = false;
|
||||
BroadcastMessage ("takeIn");
|
||||
}
|
||||
|
||||
function deselectWeapon(){
|
||||
aimed = false;
|
||||
isReload = false;
|
||||
canFire = false;
|
||||
canAim = false;
|
||||
isReload = false;
|
||||
BroadcastMessage ("takeOut");
|
||||
}
|
||||
}
|
||||
|
||||
@script RequireComponent (AudioSource)
|
||||
@script AddComponentMenu ("FPS system/Weapon System/WeaponScript")
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36fb199911a423a4bb65ece78a09a8d3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user