testing
This commit is contained in:
reedgamingstudio
2014-12-16 00:23:12 -06:00
parent c0c0755cc6
commit 5b8ebb7a35
1697 changed files with 1115979 additions and 0 deletions
@@ -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: