├── README.md └── Unity Tutorials ├── CarMovement ├── README.md └── Scripts │ ├── Front-Wheel-Drive │ └── CarController.cs │ └── Rear-Wheel-Drive │ └── CarController.cs ├── HelpScreenUI ├── README.md └── Scripts │ └── HowToManager.cs ├── Inspired_by_Games-Series ├── DeadEyeSystem │ ├── OBalfaqih-DeadEyeSystem-RDR2.unitypackage │ ├── README.md │ └── scripts │ │ └── DeadEyeSystemFinished.cs ├── Imitiating_the_Axe_of_Kratos │ ├── README.md │ └── ThrowableAxe.cs ├── README.md └── Wingsuit │ ├── CameraShake.cs │ ├── README.md │ └── WingsuitController.cs ├── Interacting-with-Doors ├── README.md └── Scripts │ └── DoorController.cs ├── Intro to UI ├── README.md └── Scripts │ └── ColorTest.cs ├── Save&Load ├── README.md └── Scripts │ └── SavingTutorial.cs ├── SceneLoader ├── README.md └── Scripts │ └── SceneLoaderScript.cs ├── Simple Game - series ├── README.md └── Scripts │ ├── Coin.cs │ ├── DestroyAfter.cs │ ├── Player.cs │ └── Spawner.cs ├── Unity_IAP ├── README.md └── Scripts │ └── StoreManager.cs ├── Upgradeable Objects ├── README.md └── Scripts │ └── SwitchingLevels.cs ├── Virtual Joysticks ├── README.md └── Scripts │ └── Player.cs └── WaypointMarker ├── Assets └── waypoint-marker.png ├── README.md └── Scripts └── MissionWaypoint.cs /README.md: -------------------------------------------------------------------------------- 1 | # Unity-Tutorials 2 | Here I will upload the scripts of the Unity tutorials that I make on my YouTube channel. 3 | Channel Link: 4 | http://youtube.com/OBalfaqih 5 | 6 | السلام عليكم ورحمة الله وبركاته 7 | هنا برفع السكريبتات الي موجودة في دروس يونيتي الي اسويها على قناتي. 8 | رابط القناة: 9 | http://youtube.com/OBalfaqih 10 | -------------------------------------------------------------------------------- /Unity Tutorials/CarMovement/README.md: -------------------------------------------------------------------------------- 1 |
This is the second tutorial in this series (Inspired by Games). In this tutorial, we copy the Dead Eye System from Red Dead Redemption 2 in a simple way.
3 |This series is to inspire all game developers to get ideas from other games and think creatively how to copy the feature but in their own and with their own touch on it.
4 |You can find the Unity package for the whole project, but if you don't want to download it, get the script directly from the scripts folder.
5 |You can find out more about the series by going to its YouTube Playlist.
6 |Watch the full tutorial here
7 | -------------------------------------------------------------------------------- /Unity Tutorials/Inspired_by_Games-Series/DeadEyeSystem/scripts/DeadEyeSystemFinished.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Created by: Omar Balfaqih (@OBalfaqih) 3 | * http://obalfaqih.com 4 | * 5 | * Unity | Dead Eye - Red Dead Redemption (Inspired by Games) 6 | * 7 | * This is the second episode of the new series: Inspired by Games 8 | * Where we will choose a feature from our favorite games 9 | * and try to copy it and learn the science behind it 10 | * 11 | * Full tutorial available at: 12 | * https://www.youtube.com/watch?v=LofJMnWPClo&index=2&list=PLaqp5z-4pFi5auiUbsq_KChZKX-DufAOI 13 | */ 14 | 15 | /* 16 | * How to use: 17 | * 1- Attach this script to the camera 18 | * 2- Create multiple UI Crosses (the "x" target ui) and assign them to the "cross" variable 19 | * 3- Change the "CameraLook" to your camera look script, in this case it is CameraLook, if you're using it then leave it as it is. 20 | * Then assign the camera script to it. 21 | * 4- Create a PostProcessingLayer and PostProcessingVolume then assign the volume to the "ppv" variable. 22 | * 5- Add an AudioSource component and assign the gun shot sound, you can find it in "SFX" folder or you can use your own. 23 | * Assign it to "shot_sfx" variable. 24 | */ 25 | 26 | 27 | using System.Collections; 28 | using System.Collections.Generic; 29 | using UnityEngine; 30 | // Using the PostProcessing library, to control the PostProcessingVolume (ppv) 31 | using UnityEngine.Rendering.PostProcessing; 32 | 33 | public class DeadEyeSystemFinished : MonoBehaviour { 34 | // Three different states of DeadEye [off: not using DeadEye, targeting: Aiming in DeadEye mode, 35 | // shooting: Auto-Shoot at targets (player won't have control over looking around and shooting)] 36 | public enum DeadEyeState 37 | { 38 | off, 39 | targeting, 40 | shooting 41 | }; 42 | // Create an instance of DeadEyeState as a variable 43 | private DeadEyeState deadEyeState = DeadEyeState.off; 44 | 45 | // List of assigned targets 46 | private ListThis is the first tutorial in this series (Inspired by Games) where we imitate the basic mechanics of the axe of Kratos from God of War
3 |This series is to inspire all game developers to get ideas from other games and think creatively how to copy the feature but in their own and with their own touch on it.
4 |You can find out more about the series by going to its YouTube Playlist.
5 |Watch the full tutorial here
6 | -------------------------------------------------------------------------------- /Unity Tutorials/Inspired_by_Games-Series/Imitiating_the_Axe_of_Kratos/ThrowableAxe.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /* 6 | * Created by: Omar Balfaqih (@OBalfaqih) 7 | * http://obalfaqih.com 8 | * 9 | * Unity | Imitating the Axe of Kratos 10 | * 11 | * This is the first tutorial of the new series: Inspired by Games 12 | * Where we will choose a feature from our favorite games 13 | * and try to copy it and learn the science behind it 14 | * 15 | * Full tutorial available at: 16 | * https://www.youtube.com/watch?v=PxdoBJBCcrw 17 | */ 18 | 19 | /* 20 | * How to use: 21 | * 1- Attach this script to the player, or the parent of your axe 22 | * 2- Make sure that your axe has Rigidbody component on it 23 | * 3- You will have a target which the handler of the axe, or where the axe should be when the player is holding it 24 | * 4- Create an empty game object which should stay attached to the hander (target) and place it next to it. It is the 25 | * point that gives the curve to your axe returning movement. Keep adjusting it until you find the perfect curve. 26 | */ 27 | 28 | public class ThrowableAxe : MonoBehaviour { 29 | 30 | // The axe object 31 | public Rigidbody axe; 32 | // Amount of force to apply when throwing 33 | public float throwForce = 50; 34 | // the target; which is the player's hand. 35 | public Transform target 36 | // The middle point between the axe and the player's hand, to give it a curve 37 | public Transform curve_point; 38 | // Last position of the axe before returning it, to use in the Bezier Quadratic Curve formula 39 | private Vector3 old_pos; 40 | // Is the axe returning? To update the calculations in the Update method 41 | private bool isReturning = false; 42 | // Timer to link to the Bezier formual, Beginnning = 0, End = 1 43 | private float time = 0.0f; 44 | 45 | // Update is called once per frame 46 | void Update () { 47 | // When the user/player hits the mouse left button 48 | if (Input.GetButtonUp("Fire1")) 49 | { 50 | ThrowAxe(); 51 | } 52 | 53 | // When the user/player hits the mouse right button 54 | if (Input.GetButtonUp("Fire2")) 55 | { 56 | ReturnAxe(); 57 | } 58 | 59 | // If the axe is returning 60 | if(isReturning){ 61 | // Returning calcs 62 | // Check if we haven't reached the end point, where time = 1 63 | if(time < 1.0f){ 64 | // Update its position by using the Bezier formula based on the current time 65 | axe.position = getBQCPoint(time, old_pos, curve_point.position, target.position); 66 | // Reset its rotation (from current to the targets rotation) with 50 units/s 67 | axe.rotation = Quaternion.Slerp(axe.transform.rotation, target.rotation, 50 * Time.deltaTime); 68 | // Increase our timer, if you want the axe to return faster, then increase "time" more 69 | // With something like: 70 | // time += Timde.deltaTime * 2; 71 | // It will return as twice as fast 72 | time += Time.deltaTime; 73 | }else{ 74 | // Otherwise, if it is 1 or more, we reached the target so reset 75 | ResetAxe(); 76 | } 77 | } 78 | } 79 | 80 | // Throw axe 81 | void ThrowAxe(){ 82 | // The axe isn't returning 83 | isReturning = false; 84 | // Deatach it form its parent 85 | axe.transform.parent = null; 86 | // Set isKinematic to false, so we can apply force to it 87 | axe.isKinematic = false; 88 | // Add force to the forward axis of the camera 89 | // We used TransformDirection to conver the axis from local to world 90 | axe.AddForce(Camera.main.transform.TransformDirection(Vector3.forward) * throwForce, ForceMode.Impulse); 91 | // Add torque to the axe, to give it much cooler effect (rotating) 92 | axe.AddTorque(axe.transform.TransformDirection(Vector3.right) * 100, ForceMode.Impulse); 93 | } 94 | 95 | // Return axe 96 | void ReturnAxe(){ 97 | // We are returning the axe; so it is in its first point where time = 0 98 | time = 0.0f; 99 | // Save its last position to refer to it in the Bezier formula 100 | old_pos = axe.position; 101 | // Now we are returning the axe, to start the calculations in the Update method 102 | isReturning = true; 103 | // Reset its velocity 104 | axe.velocity = Vector3.zero; 105 | // Set isKinematic to true, so now we control its position directly without being affected by force 106 | axe.isKinematic = true; 107 | } 108 | 109 | // Reset axe 110 | void ResetAxe(){ 111 | // Axe has reached, so it is not returning anymore 112 | isReturning = false; 113 | // Attach back to its parent, in this case it will attach it to the player (or where you attached the script to) 114 | axe.transform.parent = transform; 115 | // Set its position to the target's 116 | axe.position = target.position; 117 | // Set its rotation to the target's 118 | axe.rotation = target.rotation; 119 | } 120 | 121 | // Bezier Quadratic Curve formula 122 | // Learn more: 123 | // https://en.wikipedia.org/wiki/B%C3%A9zier_curve 124 | Vector3 getBQCPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2){ 125 | // "t" is always between 0 and 1, so "u" is other side of t 126 | // If "t" is 1, then "u" is 0 127 | float u = 1 - t; 128 | // "t" square 129 | float tt = t * t; 130 | // "u" square 131 | float uu = u * u; 132 | // this is the formula in one line 133 | // (u^2 * p0) + (2 * u * t * p1) + (t^2 * p2) 134 | Vector3 p = (uu * p0) + (2 * u * t * p1) + (tt * p2); 135 | return p; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Unity Tutorials/Inspired_by_Games-Series/README.md: -------------------------------------------------------------------------------- 1 |It is an online Unity series that is created to take interesting features in games and try to copy it in Unity. Converting science to art.
3 |The series is created mainly to be inspired by other games and try to think creatively on achieving something similar but in your own way based on your analysis and reverse-engineering skills.
4 | It combines logic with the sense of art.
You can find out more about the series by going to its YouTube Playlist.
-------------------------------------------------------------------------------- /Unity Tutorials/Inspired_by_Games-Series/Wingsuit/CameraShake.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /* 6 | * CameraShake.cs 7 | * 8 | * Created by: Omar Balfaqih (@OBalfaqih) 9 | * http://obalfaqih.com 10 | * 11 | * Making Wingsuit - Far Cry 5 (Inspired by Games) | Unity 12 | * 13 | * This is the third episode of the series: Inspired by Games 14 | * Where we choose a feature from our favorite games 15 | * and try to copy it and learn the science behind it 16 | * 17 | * Full tutorial available at: 18 | * https://www.youtube.com/watch?v=g4YWcklQoVg 19 | */ 20 | 21 | /* 22 | * How to use: 23 | * 1- Attach this script to the camera 24 | * 2- Make sure the camera is a child of your player 25 | * 3- Attach the player's 'WingsuitController' script to the 'wc' variable 26 | * 4- You can adjust the 'shaking' variable, which is the value of how much can the camera shake (Optional) 27 | */ 28 | 29 | public class CameraShake : MonoBehaviour 30 | { 31 | // The wingsuit script that the player has 32 | public WingsuitController wc; 33 | // The amount of shaking 34 | public float shaking = 0.5f; 35 | 36 | private void LateUpdate() 37 | { 38 | // Will affect the shaking based on the player's x rotation 39 | float mod_shaking = shaking * wc.percentage; 40 | // Give the camera a random position based on the percentage and shaking variables 41 | transform.localPosition = new Vector3(Random.Range(-mod_shaking, mod_shaking), Random.Range(-mod_shaking, mod_shaking), 0); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Unity Tutorials/Inspired_by_Games-Series/Wingsuit/README.md: -------------------------------------------------------------------------------- 1 |This is the third tutorial in this series (Inspired by Games) where we are going to make our player fly using a the wingsuit feature from Far Cry 5. 3 |
In this series, we study a feature from a game and then try to implement it for the sake of learning.
4 |You can find out more about the series by going to its YouTube Playlist.
5 |Watch the full tutorial here
6 | -------------------------------------------------------------------------------- /Unity Tutorials/Inspired_by_Games-Series/Wingsuit/WingsuitController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Audio; 5 | 6 | /* 7 | * WingsuitController.cs 8 | * 9 | * Created by: Omar Balfaqih (@OBalfaqih) 10 | * http://obalfaqih.com 11 | * 12 | * Making Wingsuit - Far Cry 5 (Inspired by Games) | Unity 13 | * 14 | * This is the third episode of the series: Inspired by Games 15 | * Where we choose a feature from our favorite games 16 | * and try to copy it and learn the science behind it 17 | * 18 | * Full tutorial available at: 19 | * https://www.youtube.com/watch?v=g4YWcklQoVg 20 | */ 21 | 22 | /* 23 | * How to use: 24 | * 1- Attach this script to the player 25 | * 2- Make sure that your player has a Rigidbody component 26 | * 3- Create an AudioMixer that has the sound effects, if you don't want to, just comment line: 60 and 103 27 | * 4- You don't have to modify the public variables, but you can adjust them. (Optional) 28 | */ 29 | 30 | public class WingsuitController : MonoBehaviour 31 | { 32 | // Get the player Rigidbody component 33 | public Rigidbody rb; 34 | // Rotation 35 | private Vector3 rot; 36 | 37 | // Min speed, when the player is on 0 deg or whatever minAngle you have 38 | public float lowSpeed = 12.5f; 39 | // Max speed 40 | public float highSpeed = 13.8f; 41 | 42 | // Max drag, if the player is on 0 deg or minAngle 43 | public float maxDrag = 6; 44 | // Min drag 45 | public float minDrag = 2; 46 | 47 | // Here we will store the modified force and drag 48 | private float mod_force; 49 | private float mod_drag; 50 | 51 | // Min angle for the player to rotate on the x-axis 52 | public float minAngle = 0; 53 | // Max angle 54 | public float maxAngle = 45; 55 | 56 | // Converting the x rotation from min angle to max, into a 0-1 format. 57 | // 0 means minAngle 58 | // 1 means maxAngle 59 | public float percentage; 60 | 61 | // Audio mixer, to control the sound FX pitch 62 | public AudioMixer am; 63 | 64 | private void Start() 65 | { 66 | // Make sure the player has a Rigidbody component 67 | rb = GetComponentIn this simple tutorial we are going to open and close doors.
3 |We will cover three things: 4 |
Watch the full tutorial here
-------------------------------------------------------------------------------- /Unity Tutorials/Interacting-with-Doors/Scripts/DoorController.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Created by: Omar Balfaqih (@OBalfaqih) 3 | * http://obalfaqih.com 4 | * 5 | * Interacting with Doors | Unity 6 | * 7 | * This simple script is to interact with doors (open/close) when the player presses "E" 8 | * 9 | * Full tutorial available at: 10 | * https://www.youtube.com/watch?v=nONlAXpCkag 11 | */ 12 | 13 | /* 14 | * How to use: 15 | * 1- Attach this script to your player 16 | * 2- Make sure that the player has Rigidbody and Collider components 17 | * 3- The door's parent has a collider with trigger checked 18 | * 4- Door's parent has the tag "Door" 19 | * 5- The door itself has an Animator and it has a parameter of type trigger called "OpenClose" 20 | * which is responsible for the transition between opening and closing. 21 | */ 22 | 23 | using System.Collections; 24 | using System.Collections.Generic; 25 | using UnityEngine; 26 | 27 | public class DoorController : MonoBehaviour 28 | { 29 | // The gameobject / UI that has the instructions for the player "Press 'E' to interact." 30 | public GameObject instructions; 31 | 32 | // As long as we are colliding with a trigger collider 33 | private void OnTriggerStay(Collider other) 34 | { 35 | // Check if the object has the tag 'Door' 36 | if(other.tag == "Door") 37 | { 38 | // Show the instructions 39 | instructions.SetActive(true); 40 | // Get the Animator from the child of the door (If you have the Animator component in the parent, 41 | // then change it to "GetComponent") 42 | Animator anim = other.GetComponentInChildrenIn this tutorial I will show how to add mission or quest indicator UI (The little icon that tells you where to go).
3 |We will cover: 4 |
Watch the full tutorial here
11 | -------------------------------------------------------------------------------- /Unity Tutorials/WaypointMarker/Scripts/MissionWaypoint.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class MissionWaypoint : MonoBehaviour 7 | { 8 | // Indicator icon 9 | public Image img; 10 | // The target (location, enemy, etc..) 11 | public Transform target; 12 | // UI Text to display the distance 13 | public Text meter; 14 | // To adjust the position of the icon 15 | public Vector3 offset; 16 | 17 | private void Update() 18 | { 19 | // Giving limits to the icon so it sticks on the screen 20 | // Below calculations witht the assumption that the icon anchor point is in the middle 21 | // Minimum X position: half of the icon width 22 | float minX = img.GetPixelAdjustedRect().width / 2; 23 | // Maximum X position: screen width - half of the icon width 24 | float maxX = Screen.width - minX; 25 | 26 | // Minimum Y position: half of the height 27 | float minY = img.GetPixelAdjustedRect().height / 2; 28 | // Maximum Y position: screen height - half of the icon height 29 | float maxY = Screen.height - minY; 30 | 31 | // Temporary variable to store the converted position from 3D world point to 2D screen point 32 | Vector2 pos = Camera.main.WorldToScreenPoint(target.position + offset); 33 | 34 | // Check if the target is behind us, to only show the icon once the target is in front 35 | if(Vector3.Dot((target.position - transform.position), transform.forward) < 0) 36 | { 37 | // Check if the target is on the left side of the screen 38 | if(pos.x < Screen.width / 2) 39 | { 40 | // Place it on the right (Since it's behind the player, it's the opposite) 41 | pos.x = maxX; 42 | } 43 | else 44 | { 45 | // Place it on the left side 46 | pos.x = minX; 47 | } 48 | } 49 | 50 | // Limit the X and Y positions 51 | pos.x = Mathf.Clamp(pos.x, minX, maxX); 52 | pos.y = Mathf.Clamp(pos.y, minY, maxY); 53 | 54 | // Update the marker's position 55 | img.transform.position = pos; 56 | // Change the meter text to the distance with the meter unit 'm' 57 | meter.text = ((int)Vector3.Distance(target.position, transform.position)).ToString() + "m"; 58 | } 59 | } 60 | --------------------------------------------------------------------------------