Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[UNITY 5 FPS Tutorials] GTGD S3 - Advanced First Person Shooter

Discussion in 'Community Learning & Teaching' started by GTGD, Oct 9, 2015.

  1. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Welcome to Gamer To Game Developer Series 3! I'll be showing you how to build a powerful FPS system in Unity 5 that you can expand upon for making any type of single player FPS game, from survival to all out action! In Chapter 1 I explain the basics and from there I'll show you how to build the systems that make up GTGD S3. I start out with Unity 5.2.0. I code in C#.

    S3 is now available for purchase on Steam as well!
    Includes Steam trading cards :D
    http://store.steampowered.com/app/415000




    USER CONTRIBUTED CODE
    Gun Recoil!
    Visual Studio script template
    Enemy field of view!
    Removing defeated enemies when they are out of view
    Aiming down sights
    Crouching
    Chapter 1 Unity Primer
    [2] Install Unity
    [3] Unity Basics
    [4] Code Basics
    [5] Finding & Accessing
    [6] Delaying Code
    [7] Input
    [8] Raycast
    [9] Tags
    [10] Layers & Visibility
    [11] Layers & Detection
    [12] Walk Through Walls
    [13] Triggers
    [14] Accessing Scripts
    [15] Materials & Color
    [16] Instantiate
    [17] Add Force
    [18] Collision Detection
    [19] Overlap Sphere
    [20] Explosion Force
    [21] NavMesh
    [22] AI That Pursues
    [23] Cursor Lock State
    [24] Enemy Spawner
    [25] Events
    [26] Clean Up
    [27] Your Assignment

    Chapter 2 Game Manager System
    [28] Intro To Chapter 2
    [29] Game Manager Master
    [30] Game Manager Pause Toggle
    [31] Game Manager Toggle Menu
    [32] Menu UI
    [33] Game Manager Toggle Player
    [34] Game Manager Toggle Cursor
    [35] Game Manager References
    [36] Game Manager Toggle Inventory UI
    [37] Inventory UI
    [38] Main Menu
    [39] Game Manager Go To Menu Scene
    [40] Game Manager Restart Level
    [41] Game Manager Game Over
    [42] Script Template
    [43] Panel Instructions UI
    [44] Game Manager Panel Instructions

    Chapter 3 Player System
    [45] Intro To Chapter 3
    [46] Player Master
    [47] Player Health
    [48] Canvas Health
    [49] Player Canvas Hurt
    [50] Canvas Hurt
    [51] Player Detect Item
    [52] Player Ammo Box
    [53] Unity 5.3 Conversion
    [54] Player Inventory

    Chapter 4 Item System
    [55] Intro To Chapter 4
    [56] Item Master
    [57] Item Throw
    [58] Item Pickup
    [59] Item Tag
    [60] Item Name
    [61] Item Rigidbodies
    [62] Item Colliders
    [63] Item Set Layer
    [64] Item Set Position
    [65] Item Sounds
    [66] Item Animator
    [67] Item UI
    [68] Item Ammo

    Chapter 5 Enemy System
    [69] Intro To Chapter 5
    [70] Download Golem
    [71] Setup Ragdoll
    [72] Enemy Controller
    [73] Enemy Master
    [74] Enemy Animation
    [75] Enemy Detection
    [76] Enemy Nav Pursue
    [77] Enemy Nav Destination Reached
    [78] Enemy Nav Wander
    [79] Enemy Nav Pause
    [80] Enemy Attack
    [81] Enemy Health
    [82] Enemy Take Damage
    [83] Enemy Ragdoll Activation
    [84] Enemy Collision Field
    [85] Spawner Proximity
    [86] Enemy Nav Flee

    Chapter 6 Gun System
    [87] Intro To Chapter 6
    [88] Download Gun Assets
    [89] Gun Item Setup
    [90] Gun Animations
    [91] Gun Controller
    [92] Canvas Ammo
    [93] Dynamic Crosshair UI
    [94] Dynamic Crosshair Controller
    [95] Muzzle Flash
    [96] Hit Effects
    [97] Gun Master
    [98] Gun Standard Input
    [99] Gun Shoot
    [100] Gun Muzzle Flash
    [101] Gun Hit Effects
    [102] Gun Apply Damage
    [103] Gun Animator
    [104] Gun Sounds
    [105] Gun Ammo & Reload Part 1
    [106] Gun Ammo & Reload Part 2
    [107] Gun Ammo UI
    [108] Gun Reset
    [109] Gun Dynamic Crosshair
    [110] Gun Burst Fire Indicator
    [111] Gun Apply Force
    [112] Setup Another Gun

    Chapter 7 Destructible Objects
    [113] Intro To Chapter 7
    [114] Download Barrel Assets
    [115] Setup Barrel Item
    [116] Destructible Master
    [117] Destructible Health
    [118] Destructible Take Damage
    [119] Destructible Explode
    [120] Destructible Particle Spawn
    [121] Destructible Sounds
    [122] Destructible Collision Detection
    [123] Destructible Low Health Effect
    [124] Destructible Degenerate
    [125] Destructible Player Inventory Update
    [126] Scorpion81 Fracture
    [127] Destructible Activate Shards
    [128] Item Drop
    [129] Item Transparency
    [130] Item Set Rotation
    [131] Pocket Hut Part 1
    [132] Pocket Hut Part 2
    [133] Pocket Hut Part 3

    Chapter 8 Melee System
    [134] Intro To Chapter 8
    [135] Setup Crowbar
    [136] Crowbar Animation
    [137] Melee Master
    [138] Melee Standard Input
    [139] Melee Swing
    [140] Melee Strike
    [141] Melee Reset
    [142] Melee Hit Effects
    [143] Melee Sound

    Chapter 9 NPC AI

    [144] NPC AI Introduction
    [145] Enemy NPC Prefab
    [146] NPC Master
    [147] NPC State Scripts
    [148] NPC State Pattern 1
    [149] NPC State Pattern 2
    [150] NPC State Patrol
    [151] NPC State Alert
    [152] NPC State Pursue
    [153] NPC State Flee
    [154] NPC State Follow
    [155] NPC State Melee Attack
    [156] NPC State Range Attack
    [157] NPC State Struck
    [158] NPC State Investigate Harm
    [159] NPC Animations
    [160] Edit Golem Controller
    [161] NPC Health
    [162] Improve NPC State Melee Attack
    [163] NPC Turn Off Animator
    [164] NPC Turn Off Nav Mesh Agent
    [165] NPC Turn Off State Pattern
    [166] NPC Take Damage
    [167] NPC Collision Field
    [168] NPC Ragdoll Activation
    [169] NPC Drop Items
    [170] Change To Item Master
    [171] NPC Head Look
    [172] NPC Hold Range Weapon
    [173] Gun Script Improvements
    [174] Gun NPC Input
    [175] Setup Ranged Ally 1
    [176] Setup Ranged Ally 2
    [177] General Improvements
    [178] Item Make Noise
    [179] Destructible Cause Distraction
    [180] Bug Fixes
    [181] Waypoints & Factions
    [182] Edit Gun NPC Input
    [183] Assign Waypoints
    [184] Look At Target Improvement
    [185] NPC Dynamic Faction
    [186] Edit A Few NPC Scripts
    [187] NPC Relations Data Structure
    [188] NPC Relations Master
    [189] NPC Relations Processor
    [190] NPC Set My Attacker
    [191] NPC Apply Relations
    [192] NPC Relations UI
    [193] Destructible NPC Relation
    [194] Edit Destructible Cause Distraction
    [195] Edit Item Make Noise
    [196] Upgrade To Unity 5.6

    Chapter 10 Vehicles

    [197] Introduction To Vehicles
    [198] Edit Various Scripts
    [199] Edit NPC Scripts
    [200] Setup Unity Car
    [201] Edit Standard Car Scripts
    [202] Vehicle Camera Master
    [203] Vehicle Camera Follow
    [204] Vehicle Camera Free Look
    [205] Setup Vehicle Camera
    [206] Vehicle Master
    [207] Player Vehicle Interaction
    [208] Vehicle Enter
    [209] Vehicle Exit
    [210] Vehicle Apply Damage
     
    Last edited: Oct 8, 2017
    Isaiah626, Slyer112, phani10 and 16 others like this.
  2. RongoTheBold

    RongoTheBold

    Joined:
    Oct 12, 2015
    Posts:
    1
    Thank you so much for doing this series. I've found your teaching style to be excellent and really resonates with me. I just stumbled upon your channel on Saturday, watched through your series, and decided to take your challenge! I'm brand new to Unity, but I've been a desktop & web developer for years so that part isn't a big stretch.
    Anyway, here's my submission for the end of Chapter 1. Wish I'd waited for Chapter 2 to implement my menus since I really struggled on some of those things, especially buttons and decided to put that aside for now.

    Link to the video:


    Download at: www.rongothebold.com

    I really went too far in attempting to incorporate way too many models/sounds/effects, but I figured if you're going to do something, you might as well go overboard :)

    Thanks,
    Joe
     
    KUFgoddess likes this.
  3. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ for being totally Awesome
    That's such an impressive achievement for the Chapter 1 assignment. By the end of S3 I think you will be wowing your viewers!
     
  4. TheWabbitSeason

    TheWabbitSeason

    Joined:
    Dec 1, 2013
    Posts:
    5
    Here is my submission. I changed a few things on the list, substituting audio for canvas updates, but everything should be there. That is one powerful boomstick.

     
    KingLlama likes this.
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ Excellent Quality
    Excellent video intro and really interesting control of lighting (better than I can pull it off)!
     
  6. TheWabbitSeason

    TheWabbitSeason

    Joined:
    Dec 1, 2013
    Posts:
    5
    Thanks. The light is from my 'moon' object with a directional light, but you can use any object with any type of light. I just turn it White to Red the first time, then disable the script. Then I re-enable the script when EnemyDetection can no longer find 'Enemy' tags and set reverse bool to true.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. namespace Chapter1
    6. {
    7.     public class ChangeLight : MonoBehaviour
    8.     {
    9.         public Color color0;
    10.         public Color color1;
    11.         public Light myLight;
    12.  
    13.         public bool reverse = false;
    14.  
    15.         float tChange;
    16.         float speed = 0.3f;
    17.  
    18.         void OnEnable()
    19.         {
    20.             SetInitialReferences();
    21.             tChange = 0; //Resets everytime the script is enabled so reverse bool will work
    22.         }
    23.  
    24.         void SetInitialReferences()
    25.         {
    26.             myLight = GetComponent<Light>();
    27.         }
    28.  
    29.         void Update()
    30.         {
    31.             if ( tChange < 1 )
    32.             {
    33.                 tChange += Time.deltaTime * speed;
    34.  
    35.                 if ( !reverse )
    36.                     myLight.color = Color.Lerp(color0, color1, tChange);
    37.                 else
    38.                     myLight.color = Color.Lerp(color1, color0, tChange);
    39.             }
    40.             else
    41.             {
    42.                 enabled = false; //Turn off component
    43.             }
    44.         }
    45.     }
    46. }
    47.  
     
    Last edited: Oct 27, 2015
    IanSmellis likes this.
  7. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Cool, thanks for sharing your code. I'll certainly be interested in seeing what you pull off at the end of Series 3.
     
  8. punkouter2019

    punkouter2019

    Joined:
    Jul 28, 2013
    Posts:
    170
    dumb question.. but I looked everywhere..

    Is there the source for this? Id like to use it as a reference
     
  9. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    The source will be exclusive to the Steam package which I'm aiming to have ready by March 2016.
     
  10. punkouter2019

    punkouter2019

    Joined:
    Jul 28, 2013
    Posts:
    170
    Ok. Ill try the old ones for now.. maybe they are compatible with Unity 5 ?
     
  11. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I wouldn't recommend trying to follow Series 1 or 2 in Unity 5, they won't be compatible.
     
  12. TheWabbitSeason

    TheWabbitSeason

    Joined:
    Dec 1, 2013
    Posts:
    5
    I made some final Chapter 1 tweaks and updates before starting Chapter 2. I'm very proud of the ghost heartbeats. They are all randomly timed and fadeout as the ghost 'dies'...again. I'm still hunting for a way to tone down the physics and reduce the force applied to the bricks when shot and the dead ghosts.

     
    IanSmellis likes this.
  13. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Really, really good stuff. I reckon you're onto making a pretty neat game. I adjust the masses of objects till they feel right, so the brick walls for example can be heavier so that the shotgun bullets don't make them fly so far.
     
  14. TheWabbitSeason

    TheWabbitSeason

    Joined:
    Dec 1, 2013
    Posts:
    5
    Thanks for the ideas on the physics. I will try applying force depending on the tag and adjusting the mass. I want the story to stay in the Enchanted Forest, but eventually Ash will have to be replaced.
     
  15. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Elmer Fudge (to avoid copyright infringements of course) :)
     
  16. marcs77

    marcs77

    Joined:
    Jul 14, 2013
    Posts:
    4
    Hi everyone! Here is my project:

    I have added a few extra features such as controller support, a few animations, death (kind of) and other stuff :).
    Hope you enjoy it!! Thanks GTGD for your awesome tutorials ;)
     
  17. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ for ASTOUNDING
    I found myself compelled to download it and play. Fantastic work! It was simple yet felt so polished. I love how the grenade launcher barrel rotates, and it's cool that you make the level restart if the player falls in the pit or gets caught by an enemy. The choice of sounds and visuals was really great. Keep up the great work!
     
  18. nuke-dukem

    nuke-dukem

    Joined:
    Jul 27, 2015
    Posts:
    1
    Here is a link to my Chapter 1 Series 3 assignment. I had fun going through this material and I learned a lot as well. I definitely have the game programming bug now! Looking forward to Chapter 2. Thanks so much for these lessons!
     
  19. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A for GOOD SOLID EFFORT
    Nice work there, you've implemented character animations and they're actually walking. Once I get to the enemies chapter you'll be able to update your project and make it a lot more fun as the enemies get blasted about as ragdolls :). Thank you for sharing!
     
  20. mi.ga

    mi.ga

    Joined:
    Dec 6, 2015
    Posts:
    1
    Hello there, thanks a lot for your tutorials, here's my simple version. Looking forward to learn more!

     
    Saurabh-Saralaya likes this.
  21. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A For Excellent Work
    Nice work with the spot light! That sure is one massive blast! Thanks for sharing :)
     
  22. KandoGames

    KandoGames

    Joined:
    Dec 7, 2015
    Posts:
    9
    I Skimmed through the videos, and you don't seem to be creating one complete games but instead teaching different parts of the game development? is that so? And then getting users to create their own projects using either their own assets or from the store? Or am I missing something
     
  23. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Watch the first video. That explains what you'll be developing. I can't teach you modelling or art but I'll show you how to write the scripts that make up the FPS system.
     
    Last edited: Dec 10, 2015
  24. KandoGames

    KandoGames

    Joined:
    Dec 7, 2015
    Posts:
    9
    Thanks! I did watch the first video. And a few of the others.

    They all look great. Will be following along soon !
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Video 51 Player Detect Item script for those who'd rather copy and paste it.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace S3
    5. {
    6.     public class Player_DetectItem : MonoBehaviour
    7.     {
    8.         [Tooltip("What layer is being used for items.")]
    9.         public LayerMask layerToDetect;
    10.         [Tooltip("What transform will the ray be fired from?")]
    11.         public Transform rayTransformPivot;
    12.         [Tooltip("The editor input button that will be used for picking up items.")]
    13.         public string buttonPickup;
    14.  
    15.         private Transform itemAvailableForPickup;
    16.         private RaycastHit hit;
    17.         private float detectRange = 3;
    18.         private float detectRadius = 0.7f;
    19.         private bool itemInRange;
    20.  
    21.         private float labelWidth = 200;
    22.         private float labelHeight = 50;
    23.  
    24.         void Update()
    25.         {
    26.             CastRayForDetectingItems();
    27.             CheckForItemPickupAttempt();
    28.         }
    29.  
    30.         void CastRayForDetectingItems()
    31.         {
    32.             if (Physics.SphereCast(rayTransformPivot.position, detectRadius, rayTransformPivot.forward, out hit, detectRange, layerToDetect))
    33.             {
    34.                 itemAvailableForPickup = hit.transform;
    35.                 itemInRange = true;
    36.             }
    37.  
    38.             else
    39.             {
    40.                 itemInRange = false;
    41.             }
    42.         }
    43.  
    44.         void CheckForItemPickupAttempt()
    45.         {
    46.             if (Input.GetButtonDown(buttonPickup) && Time.timeScale > 0 && itemInRange && itemAvailableForPickup.root.tag != GameManager_References._playerTag)
    47.             {
    48.                 //Debug.Log("Pickup attempted");
    49.                 itemAvailableForPickup.GetComponent<Item_Master>().CallEvenPickupAction(rayTransformPivot);
    50.             }
    51.         }
    52.  
    53.         void OnGUI()
    54.         {
    55.             if (itemInRange && itemAvailableForPickup != null)
    56.             {
    57.                 GUI.Label(new Rect(Screen.width / 2 - labelWidth / 2, Screen.height / 2, labelWidth, labelHeight), itemAvailableForPickup.name);
    58.             }
    59.         }
    60.     }
    61. }
    62.  
     
  26. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Barrels can go boom when you throw them :)
     
  27. giovani94

    giovani94

    Joined:
    Jan 9, 2016
    Posts:
    1
  28. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    LOL you wrote those warning messages to tell you if you forgot to type in the required data in the inspector for that script! If you double click the warning message it will take you to the place where you wrote it in the script
     
  29. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    Can you help me I did your nav purse video and getting all kinds of errors. I know the tag one keeps popping up but I actually went into Game References and changed it there so that the enemy can find my player. I do not get why the other errors are happening the skeleton is not moving toward me. upload_2016-1-22_18-46-41.png
     

    Attached Files:

  30. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    Do not understand but deactivated reactivated the scripts errors went away but know the skeleton character keeps going into the ground when game is started his knees go into the floor. Can you help me? do you know whats wrong i got the errors gone but the skeleton keeps going into the ground why does it change position i baked all of the animation just confused. (I think i fixed errors but actually adding a path to it lol) so after messing around with it the animation is dropping the character but why and how do i fix it pls help?
     
    Last edited: Jan 23, 2016
  31. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    I figured it out so the animations were making it go down in the ground so you go to the character and animations then you go to the loop settings and it has base upon start on one and u put on feet as start. It took a hour to figure that out by my self. no unity posts helped me . Just wanted to post because i would hate for someone else to go through this lol
     
  32. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace S3
    5. {
    6. public class Enemy_Attack : MonoBehaviour {
    7.         private Enemy_Master enemyMaster;
    8.         private Transform attackTarget;
    9.         private Transform myTransform;
    10.         public float attackRate = 1;
    11.         private float nextAttack;
    12.         public float attackRange = 3.5f;
    13.         public int attackDamage = 10;
    14.     void OnEnable()
    15.     {
    16.             SetInitialReferences ();
    17.             enemyMaster.EventEnemyDie += DisableThis;
    18.             enemyMaster.EventEnemySetNavTarget += SetAttackTarget;
    19.     }
    20.    
    21.     void OnDisable()
    22.     {
    23.             enemyMaster.EventEnemyDie -= DisableThis;
    24.             enemyMaster.EventEnemySetNavTarget -= SetAttackTarget;
    25.     }
    26.  
    27.    
    28.     // Update is called once per frame
    29.     void Update () {
    30.             TryToAttack ();
    31.     }
    32.    
    33.     void SetInitialReferences()
    34.     {
    35.             enemyMaster = GetComponent<Enemy_Master> ();
    36.             myTransform = transform;
    37.     }
    38.    
    39.     void SetAttackTarget(Transform targetTransform)
    40.         {
    41.             attackTarget = targetTransform;
    42.         }
    43.  
    44.         void TryToAttack()
    45.         {
    46.             if (attackTarget != null) {
    47.                 if (Time.time > nextAttack) {
    48.                     nextAttack = Time.time + attackRate;
    49.                     if (Vector3.Distance (myTransform.position, attackTarget.position) <= attackRange) {
    50.                         Vector3 lookAtVector = new Vector3 (attackTarget.position.x, myTransform.position.y, attackTarget.position.z);
    51.                         myTransform.LookAt (lookAtVector);
    52.                         enemyMaster.CallEventEnemyAttack ();
    53.                         enemyMaster.isOnRoute = false;
    54.                     }
    55.                 }
    56.             }
    57.         }
    58.  
    59.         public void OnEnemyAttack()//called Swing normal
    60.         {
    61.             if (attackTarget != null) {
    62.                 if (Vector3.Distance (myTransform.position, attackTarget.position) <= attackRange &&
    63.                     attackTarget.GetComponent<Player_Master> () != null) {
    64.                     Vector3 toOther = attackTarget.position - myTransform.position;
    65.                     //Debug.Log (Vector3.Dot (toOther, myTransform.forward).ToString ());
    66.  
    67.                     if (Vector3.Dot (toOther,myTransform.forward) > 0.5F) {
    68.                         attackTarget.GetComponent<Player_Master>().CallEventPlayerHealthDeduction(attackDamage);
    69.                     }
    70.                 }
    71.             }
    72.  
    73.         }
    74.  
    75.         void DisableThis()
    76.         {
    77.             this.enabled = false;
    78.         }
    79.     }
    80. }
    81.  
     
  33. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Does your OnEnemyAttack method ever get called?
     
    Last edited: Jan 23, 2016
  34. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    Oh i got it to work for some reason it does not go through the whole animation and had to set event so it happened early but it is fine now. and can you do a scoring system like a kill counter. and and at end play screen u get to see your deaths and kills you got. it is probably simply but do not know how to code lol
     
  35. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    Is it bad that i am having fun putting like a 100 skeletons in one room and see if i can survive. 400 is just overkill lol
     
    Last edited: Jan 23, 2016
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Yeah it is pretty fun, especially when you can throw stuff at the enemies and hurt them. You could make different enemy types and make it interesting. In chapter 7 items will become much more interesting because you'll be making exploding barrels as an example of what you can do.
     
  37. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Yes you're going to learn how to do this
     
    Racine-Z and matthewaranzanso like this.
  38. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    I've made guys to you some recoil to the gun if you want
    Please make a backup, so you don't blame me if it doesn't work, please ..
    Follow this to do it:
    1. Create a C# Script to the Gun Scripts Folder and Call it "Gun_Recoil"
    2. Add this code, it's easy to understand :
      Code (CSharp):
      1. using UnityEngine;
      2. using System.Collections;
      3.  
      4. namespace SI
      5. {
      6.     public class Gun_Recoil : MonoBehaviour {
      7.  
      8.         private Gun_Master gunMaster;
      9.  
      10.         #region Recoil Variables
      11.  
      12.         private Vector3 currentRecoil1;
      13.         private Vector3 currentRecoil2;
      14.         private Vector3 currentRecoil3;
      15.         private Vector3 currentRecoil4;
      16.  
      17.         public Vector3 recoilRotation;
      18.         public Vector3 recoilKickback;
      19.  
      20.         #endregion
      21.  
      22.         public Transform weaponHolder;
      23.  
      24.         // Update is called once per frame
      25.         void FixedUpdate () {
      26.             RecoilController();
      27.  
      28.         }
      29.  
      30.         void OnEnable()
      31.         {
      32.             SetIntialReferences();
      33.             gunMaster.EventPlayerInput += AddRecoil;
      34.         }
      35.  
      36.         void OnDisable()
      37.         {
      38.             gunMaster.EventPlayerInput -= AddRecoil;
      39.         }
      40.  
      41.         void SetIntialReferences()
      42.         {
      43.             gunMaster= GetComponent<Gun_Master>();
      44.         }
      45.  
      46.         void AddRecoil()
      47.         {
      48.             currentRecoil1 += new Vector3(recoilRotation.x, Random.Range(-recoilRotation.y, recoilRotation.y));
      49.             currentRecoil3 += new Vector3(Random.Range(-recoilKickback.x, recoilKickback.x), Random.Range(-recoilKickback.y, recoilKickback.y), recoilKickback.z);
      50.         }
      51.  
      52.         void RecoilController()
      53.         {
      54.             currentRecoil1 = Vector3.Lerp(currentRecoil1, Vector3.zero,0.1f);
      55.             currentRecoil2 = Vector3.Lerp(currentRecoil2, currentRecoil1, 0.1f);
      56.             currentRecoil3 = Vector3.Lerp(currentRecoil3, Vector3.zero, 0.1f);
      57.             currentRecoil4 = Vector3.Lerp(currentRecoil4, currentRecoil3, 0.1f);
      58.  
      59.             weaponHolder.localEulerAngles = currentRecoil2;
      60.             weaponHolder.localPosition = currentRecoil4;
      61.         }
      62.  
      63.     }
      64. }
    3. Make an Empty GameObject call it Holder and and it to the Assault Rifle
    4. Now, Go to Gun_Shoot Script and edit it to this ..

      Code (CSharp):
      1. using UnityEngine;
      2. using System.Collections;
      3.  
      4. namespace SI
      5. {
      6.     public class Gun_Shoot: MonoBehaviour {
      7.  
      8.         private Gun_Master gunMaster;
      9.         private RaycastHit hit;
      10.         public float range = 400;
      11.  
      12.         private Transform camTransform;
      13.         public Transform weaponHolder;
      14.  
      15.  
      16.         void OnEnable()
      17.         {
      18.             SetIntialReferences();
      19.             gunManager.EventPlayerInput += OpenFire;
      20.             //gunManager.EventSpeedCaptured += SetStartOfShootingPosition;
      21.         }
      22.  
      23.         void OnDisable()
      24.         {
      25.             gunManager.EventPlayerInput -= OpenFire;
      26.             //gunManager.EventSpeedCaptured -= SetStartOfShootingPosition;
      27.         }
      28.  
      29.         void SetIntialReferences()
      30.         {
      31.             gunMaster = GetComponent<Gun_Master>();
      32.             camTransform = transform.parent;
      33.         }
      34.  
      35.         void OpenFire()
      36.         {
      37.             if (Physics.Raycast(camTransform.position + weaponHolder.localPosition, weaponHolder.forward, out hit, range))
      38.             {
      39.                 gunManager.CallEventShotDefault(hit.point, hit.transform);
      40.                 if(hit.transform.CompareTag(GameManager_References._enemyTag))
      41.                 {
      42.                     gunMaster.CallEventShotEnemy(hit.point, hit.transform);
      43.                 }
      44.             }
      45.  
      46.         }
      47.     }
      48. }
      Don't forgot to disable Gun_Animator Script ..
     
    Last edited: Feb 7, 2016
    pushingpandas likes this.
  39. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for a neat contribution there! I've added a link up above under the videos so that others can find your post in the future. Out of curiosity, are you still using the gun animator for the idle and shooting animations?
     
  40. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    Oh i forgot that, you've to disable the Gun_Animator script for that :)
     
  41. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Here's the new demo scene I'm preparing for the Steam release of the S3 tutorials (March 2016). I'm aiming to show how the systems can come together to make something fun!
     
    matthewaranzanso likes this.
  42. Andy1990

    Andy1990

    Joined:
    Feb 10, 2016
    Posts:
    2
    Hi,

    First of all thank you very much for making these tutorial videos, they are great to watch and learn from.

    I started watching and following the videos on Unity just a few days ago and have got up to video 58 (Item Pickup), but I am having big issues.

    I am unable to pick up any items, I have checked the Item master script / player detection script and the pick up script but still no luck.

    When I have the detection debug on it shows in the console that Pickup Attempted but the item just is not been picked up. I have set the item Layer and Tag both to Item also.

    If you have any suggestions that would be great and if there is any more info I can provide to help please let me know.

    Thank you.

    Andy
     
  43. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Perhaps check the case of the Item layer and Tag and check that the way it's written matches what you typed in the inspector for those scripts. Double check if the code that places the item on the player and then deactivates is called. Use debug.log to follow the trail and find out where your code isn't running.
     
  44. Andy1990

    Andy1990

    Joined:
    Feb 10, 2016
    Posts:
    2
    Thank you for your quick reply, I shall double check all the above tonight after work and hopefully manage to get it all working, thanks again.
     
  45. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
  46. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    I do not know how to make it so the script for level transfer has to require a score and get the variable from the script. then use it, i tried different things but honestly i do not think i can figure this one out. need help please
     
  47. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    but currently when enemy gets destroyed it will give you a hundred points and i have enemy script attached to enemy. the ui is obviously attached to script. Let me know if you need more info to help me
     
  48. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    It's simple all you need to do is to make another GameManager script or really any script with the score variable. Make a new enemy script so that subscribes to the die event. When die happens then this new enemy script will call a method on that new GameManager or whatever script and run a method that increases the score and also checks if the score target has been achieved. If achieve then go to the next level. Simple stuff. Study chapter 1 again which teaches all this sort of basic coding stuff.

    Video 53 shows how to use the new SceneManager code rather than Application.LoadLevel
     
  49. Torrey

    Torrey

    Joined:
    Jan 22, 2016
    Posts:
    13
    Thank you, but I need to look into the beginning videos because I really am just lost and really do not know how to do it. you tell me how but I just can not get it. Coding just gets me confused at times. Tell you the truth have not looked at beginning videos I need to lol
     
  50. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Yeah study the first chapter and you may need to go over it more than once for it to sink in fully