├── .editorconfig ├── .gitattributes ├── .gitignore ├── AI └── Scripts │ ├── simplechase.js │ ├── simplefollow.js │ └── simplefollow2d ├── Camera ├── FreeFlightCamera.js └── smoothfollow2d.js ├── Character Control ├── sidescrollcontrols.js └── topdowncontrols.js ├── Misc ├── destroytaggedobjects.js ├── fadeinout.js ├── generateobjects.js └── randomsizeonload.js ├── Odds and Ends └── 4-shade-greyscale.ase ├── README.md └── unity-awesomeness.sublime-project /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs. 2 | # EditorConfig is AweSome: http://editorconfig.org/ 3 | 4 | root = true 5 | 6 | [*] 7 | charset = UTF-8 8 | end_of_line = LF 9 | insert_final_newline = true 10 | trim_trailing_whitespace = false 11 | indent_size = 4 12 | indent_style = tab 13 | 14 | [*.py] 15 | indent_style = space 16 | 17 | [*.{ini,json,rb,yml}] 18 | indent_size = 2 19 | indent_style = space 20 | 21 | [.*rc] 22 | indent_size = 2 23 | indent_style = space 24 | 25 | [{Gemfile*,Rakefile}] 26 | indent_size = 2 27 | indent_style = space 28 | 29 | [*.bat] 30 | end_of_line = crlf 31 | 32 | [CNAME] 33 | insert_final_newline = false 34 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://github.com/mhulse/gh-boiler/issues/42 2 | 3 | * text=auto 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # https://github.com/github/gitignore 2 | 3 | # COMPILED SOURCE # 4 | ################### 5 | 6 | *.class 7 | *.com 8 | *.dll 9 | *.exe 10 | *.o 11 | *.py[cdo] 12 | *.so 13 | 14 | # PACKAGES # 15 | ############ 16 | 17 | *.7z 18 | *.dmg 19 | *.egg* 20 | *.gz 21 | *.iso 22 | *.jar 23 | *.rar 24 | *.tar 25 | *.zip 26 | 27 | # LOGS AND DATABASES # 28 | ###################### 29 | 30 | *.log 31 | *.sql 32 | *.sqlite 33 | *.db 34 | 35 | # OS GENERATED FILES # 36 | ###################### 37 | 38 | ._* 39 | .DS_Store 40 | .DS_Store? 41 | .Spotlight-V100 42 | .Trashes 43 | Desktop.ini 44 | ehthumbs.db 45 | Icon^M^M 46 | Thumbs.db 47 | 48 | # EDITORS # 49 | ########### 50 | 51 | *.sublime-workspace 52 | *.swo 53 | *.swp 54 | *~ 55 | .\#* 56 | .elc 57 | .project 58 | .pydevproject 59 | .settings 60 | /.emacs.desktop 61 | /.emacs.desktop.lock 62 | \#*\# 63 | auto-save-list 64 | tramp 65 | 66 | # MISCELLANEOUS # 67 | ################# 68 | 69 | *.bak 70 | .cvs 71 | .svn 72 | sitemap.xml.gz*~ 73 | 74 | # PROJECT-SPECIFIC # 75 | #################### 76 | -------------------------------------------------------------------------------- /AI/Scripts/simplechase.js: -------------------------------------------------------------------------------- 1 | @script RequireComponent(CharacterController) 2 | 3 | var speed: float = 6.0; 4 | var gravity: float = 20.0; 5 | var movespeed: Vector3; 6 | var target : GameObject; 7 | 8 | private var sprite : GameObject; 9 | 10 | 11 | function Start(){ 12 | 13 | speed = Random.Range(4.0, 7.6); 14 | 15 | sprite = gameObject.transform.Find("sprite").gameObject; 16 | 17 | } 18 | 19 | 20 | function Update() { 21 | 22 | var controller: CharacterController = GetComponent(CharacterController); 23 | 24 | var relativedir : Vector3; 25 | 26 | relativedir = transform.TransformDirection(target.transform.position - transform.position); 27 | 28 | moveDirection = relativedir.normalized; 29 | 30 | moveDirection = transform.TransformDirection(moveDirection); 31 | 32 | moveDirection *= speed; 33 | 34 | movespeed = moveDirection; 35 | 36 | // Apply gravity 37 | moveDirection.y -= gravity * Time.deltaTime; 38 | 39 | // Move the controller 40 | controller.Move(moveDirection * Time.deltaTime); 41 | 42 | 43 | //Flip the sprite if you have the option selected in editor. 44 | if (sprite != null) { 45 | 46 | if (movespeed.x < 0.0){ 47 | 48 | sprite.GetComponent.().flipX = true; 49 | 50 | } 51 | 52 | else if (movespeed.x > 0.0){ 53 | 54 | sprite.GetComponent.().flipX = false; 55 | 56 | } 57 | 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /AI/Scripts/simplefollow.js: -------------------------------------------------------------------------------- 1 | var Player: Transform; 2 | var MoveSpeed = 4.0; 3 | var height = 1.0; 4 | var MaxDist = 10.0; 5 | var MinDist = 5.0; 6 | var height = 1.0; 7 | 8 | 9 | 10 | 11 | function Start() { 12 | 13 | } 14 | 15 | function Update() { 16 | 17 | transform.LookAt(Player); 18 | 19 | if (Vector3.Distance(transform.position, Player.position) >= MinDist && Vector3.Distance(transform.position, Player.position) <= MaxDist) { 20 | 21 | transform.position += transform.forward * MoveSpeed * Time.deltaTime; 22 | 23 | transform.position.y = height; 24 | 25 | if (Vector3.Distance(transform.position, Player.position) <= MaxDist) { 26 | 27 | //This area can be used to configure actions when player is in range. 28 | 29 | } 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | 37 | function Attack (){ 38 | 39 | 40 | 41 | } -------------------------------------------------------------------------------- /AI/Scripts/simplefollow2d: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------- 2 | // 3 | // Visit the unity-awesomeness repo at: 4 | // github.com/patflannery/unity-awesomeness 5 | // 6 | //---------------------------------------------------------------------- 7 | // 8 | //Name: Simple Follow AI Script - Top Down 9 | // 10 | //Description: When attached to a game object, it will follow the "player" object along the (X,Z) axis. 11 | // 12 | //---------------------------------------------------------------------- 13 | 14 | var player : Transform; 15 | var speed = 2.0; 16 | 17 | function Start() { 18 | 19 | } 20 | 21 | 22 | function Update() { 23 | 24 | var gohere = player.position; 25 | 26 | transform.position += (gohere - transform.position).normalized * speed; 27 | 28 | } -------------------------------------------------------------------------------- /Camera/FreeFlightCamera.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | 3 | class FreeFlightCamera extends MonoBehaviour { 4 | 5 | var speedNormal:float = 10.0f; 6 | var speedFast:float = 50.0f; 7 | var mouseSensitivityX:float = 5.0f; 8 | var mouseSensitivityY:float = 5.0f; 9 | 10 | function Start() { 11 | 12 | var component:Rigidbody = gameObject.GetComponent(Rigidbody); 13 | 14 | if (component) { 15 | 16 | component.freezeRotation = true; 17 | 18 | } 19 | 20 | } 21 | 22 | function Update() { 23 | 24 | var rotY:float = 0.0f; 25 | var rotX:float = 0.0f; 26 | var forward:float; 27 | var strafe:float; 28 | var speed:float; 29 | var trans:Vector3; 30 | var gravity = 8; 31 | 32 | forward = Input.GetAxis('Vertical'); 33 | strafe = Input.GetAxis('Horizontal'); 34 | 35 | // Rotation: 36 | if (Input.GetMouseButton(0)) { 37 | 38 | rotX = transform.localEulerAngles.y + Input.GetAxis('Mouse X') * mouseSensitivityX; 39 | rotY += Input.GetAxis('Mouse Y') * mouseSensitivityY; 40 | rotY = Mathf.Clamp(rotY, -89.5f, 89.5f); 41 | 42 | transform.localEulerAngles = new Vector3(-rotY, rotX, 0.0f); 43 | 44 | } 45 | 46 | // Move forwards/backwards: 47 | if (forward != 0.0f) { 48 | 49 | speed = Input.GetKey(KeyCode.LeftShift) ? speedFast : speedNormal; 50 | trans = new Vector3(0.0f, 0.0f, forward * speed * Time.deltaTime); 51 | 52 | gameObject.transform.localPosition += gameObject.transform.localRotation * trans; 53 | 54 | } 55 | 56 | // Strafe left/right: 57 | if (strafe != 0.0f) { 58 | 59 | speed = Input.GetKey(KeyCode.LeftShift) ? speedFast : speedNormal; 60 | trans = new Vector3(strafe * speed * Time.deltaTime, 0.0f, 0.0f); 61 | 62 | gameObject.transform.localPosition += gameObject.transform.localRotation * trans; 63 | 64 | } 65 | 66 | // Gravity: 67 | 68 | gameObject.transform.localPosition += -gravity * trans * Time.deltaTime; 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Camera/smoothfollow2d.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | enum axis {XZ, XY} 3 | var target : Transform; 4 | var Axis: axis; 5 | var smoothTime = 0.3; 6 | private var thisTransform : Transform; 7 | private var velocity : Vector3; 8 | 9 | 10 | 11 | function Start() { 12 | 13 | thisTransform = transform; 14 | 15 | } 16 | 17 | function Update() { 18 | 19 | if (Axis == axis.XZ) { 20 | 21 | thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, target.position.x, velocity.x, smoothTime); 22 | 23 | thisTransform.position.z = Mathf.SmoothDamp( thisTransform.position.z, target.position.z, velocity.z, smoothTime); 24 | 25 | } 26 | 27 | 28 | if (Axis == axis.XY) { 29 | 30 | thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, target.position.x, velocity.x, smoothTime); 31 | 32 | thisTransform.position.y = Mathf.SmoothDamp(thisTransform.position.y, target.position.y, velocity.y, smoothTime); 33 | 34 | 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /Character Control/sidescrollcontrols.js: -------------------------------------------------------------------------------- 1 | @script RequireComponent(CharacterController) 2 | 3 | @Tooltip ("Set the speed of the player when running.") 4 | var speed: float = 6.0; 5 | 6 | @Tooltip ("Strength of gravity on the player.") 7 | var gravity: float = 20.0; 8 | 9 | @Tooltip ("The strength of the player's jump.") 10 | var jumpamount : float = 10.0; 11 | 12 | @Tooltip ("Lock the player's Z axis position.") 13 | var lockz : float = 0.0; 14 | 15 | private var sprite : GameObject; 16 | private var moveDirection : Vector3; 17 | private var movespeed: Vector3; 18 | 19 | 20 | function Start(){ 21 | 22 | if (gameObject.transform.Find("sprite") != null){ 23 | 24 | sprite = gameObject.transform.Find("sprite").gameObject; 25 | 26 | } 27 | 28 | } 29 | 30 | 31 | 32 | function Update() { 33 | 34 | 35 | gameObject.transform.position.z = lockz; 36 | 37 | var controller: CharacterController = GetComponent(CharacterController); 38 | 39 | if (controller.isGrounded == true) { 40 | 41 | moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,0); 42 | 43 | moveDirection = transform.TransformDirection(moveDirection); 44 | 45 | moveDirection *= speed; 46 | 47 | movespeed = moveDirection; 48 | 49 | } 50 | 51 | 52 | if (controller.isGrounded == false) { 53 | 54 | moveDirection.x = Vector3(Input.GetAxis("Horizontal"), 0,0).x; 55 | 56 | moveDirection = transform.TransformDirection(moveDirection); 57 | 58 | moveDirection.x *= speed; 59 | 60 | movespeed = moveDirection; 61 | 62 | } 63 | 64 | 65 | if (controller.isGrounded && Input.GetButtonDown("Jump")){ 66 | 67 | jump(); 68 | 69 | } 70 | 71 | 72 | // Apply gravity 73 | moveDirection.y -= gravity * Time.deltaTime; 74 | 75 | // Move the controller 76 | controller.Move(moveDirection * Time.deltaTime); 77 | 78 | 79 | //Flip the sprite if one attached. 80 | 81 | if (sprite != null){ 82 | 83 | if (movespeed.x < -0.5){ 84 | 85 | sprite.GetComponent.().flipX = true; 86 | 87 | } 88 | 89 | else if (movespeed.x > 0.5){ 90 | 91 | sprite.GetComponent.().flipX = false; 92 | 93 | } 94 | 95 | } 96 | 97 | } 98 | 99 | 100 | 101 | 102 | function jump() { 103 | 104 | moveDirection.y += jumpamount; 105 | 106 | 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Character Control/topdowncontrols.js: -------------------------------------------------------------------------------- 1 | @script RequireComponent(CharacterController) 2 | 3 | 4 | var speed: float = 6.0; 5 | var gravity: float = 20.0; 6 | var movespeed: Vector3; 7 | 8 | function Update() { 9 | 10 | var controller: CharacterController = GetComponent(CharacterController); 11 | 12 | if (controller.isGrounded) { 13 | 14 | moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); 15 | 16 | moveDirection = transform.TransformDirection(moveDirection); 17 | 18 | moveDirection *= speed; 19 | 20 | movespeed = moveDirection; 21 | 22 | } 23 | 24 | // Apply gravity 25 | moveDirection.y -= gravity * Time.deltaTime; 26 | 27 | // Move the controller 28 | controller.Move(moveDirection * Time.deltaTime); 29 | 30 | 31 | 32 | } -------------------------------------------------------------------------------- /Misc/destroytaggedobjects.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | 3 | var tag1: String; 4 | var tag2: String; 5 | var tag3: String; 6 | var tag4: String; 7 | var tag5: String; 8 | 9 | function Start() { 10 | 11 | } 12 | 13 | function Update() { 14 | 15 | } 16 | 17 | 18 | function OnTriggerEnter(other: Collider) { 19 | 20 | if (other.tag == tag1 || other.tag == tag2 || other.tag == tag3 || other.tag == tag4 || other.tag == tag5) { 21 | 22 | Debug.Log("hit something"); 23 | 24 | Destroy(other.gameObject); 25 | 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Misc/fadeinout.js: -------------------------------------------------------------------------------- 1 | #pragma strict 2 | 3 | var overlay : GameObject; 4 | private var fadeout : boolean; 5 | private var fadein : boolean; 6 | private var lerpval : float; 7 | var color : Color; 8 | 9 | 10 | function Update() { 11 | 12 | overlay.GetComponent.().color = color; 13 | 14 | lerpval = lerpval + .0001; 15 | 16 | if (fadeout == true) { 17 | 18 | fadein = false; 19 | 20 | color.a = Mathf.Lerp(color.a, 1, lerpval); 21 | 22 | if (color.a > .999) { 23 | 24 | fadeout = false; 25 | 26 | } 27 | 28 | } 29 | 30 | else if (fadein == true) { 31 | 32 | fadeout = false; 33 | 34 | color.a = Mathf.Lerp(color.a, 0, lerpval); 35 | 36 | if (color.a < .001) { 37 | 38 | fadein = false; 39 | 40 | } 41 | 42 | 43 | } 44 | 45 | else { 46 | 47 | 48 | 49 | } 50 | 51 | 52 | if (Input.GetKeyDown("i")) { 53 | 54 | fin(); 55 | 56 | } 57 | 58 | if (Input.GetKeyDown("o")) { 59 | 60 | fout(0); 61 | 62 | } 63 | 64 | 65 | } 66 | 67 | 68 | function fin(){ 69 | 70 | lerpval = 0.0; 71 | 72 | fadein = true; 73 | 74 | } 75 | 76 | 77 | function fout(levelnum : int){ 78 | 79 | lerpval = 0.0; 80 | 81 | fadeout = true; 82 | 83 | yield WaitForSeconds(4); 84 | 85 | Application.LoadLevel(levelnum); 86 | 87 | } 88 | -------------------------------------------------------------------------------- /Misc/generateobjects.js: -------------------------------------------------------------------------------- 1 | //A simple script for generating a large number of objects on load. 2 | 3 | #pragma strict 4 | 5 | var obj1: GameObject; //Add more as "obj##" below this line for a variety of objects 6 | 7 | var numthings = 100; //How many things? 8 | 9 | function Start() { 10 | 11 | for (var i: int = 0; i < numthings; i++) { 12 | Instantiate(obj1); //Make sure to instantiate additional objects below this line. 13 | 14 | } 15 | } 16 | 17 | function Update() { 18 | 19 | } -------------------------------------------------------------------------------- /Misc/randomsizeonload.js: -------------------------------------------------------------------------------- 1 | //Primarily for use in tandem with generateobjects.js. 2 | 3 | #pragma strict 4 | 5 | var SizeMin = 0.0; 6 | var SizeMax = 0.0; 7 | var XMin = 0.0; 8 | var XMax = 0.0; 9 | var Zmin = 0.0; 10 | var Zmax = 0.0; 11 | 12 | 13 | function Awake() { 14 | 15 | var scl = 0.0; 16 | 17 | scl = Random.Range(SizeMin, SizeMax); 18 | 19 | transform.position.x = (Random.Range(Xmin, Xmax)); 20 | 21 | transform.position.z = (Random.Range(Zmax, Zmax)); 22 | 23 | transform.localScale += Vector3(scl, 1, scl); 24 | 25 | } 26 | 27 | function Update() { 28 | 29 | } -------------------------------------------------------------------------------- /Odds and Ends/4-shade-greyscale.ase: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pixelfoot/unity-awesomeness/e052f9888543ecd932602ad5aa22770513077a2e/Odds and Ends/4-shade-greyscale.ase -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Unity Awesomeness 4 | 5 | **A collection of utility scripts for [Unity 5](https://unity3d.com/).** 6 | 7 | Unity is a flexible and powerful development platform for creating multi-platform 3D and 2D games and interactive experiences. 8 | 9 | ## Table of contents 10 | 11 | - [Artificial Intelligence](#artificial-intelligence) 12 | - [Animation](#animation) 13 | - [Camera](#camera) 14 | - [Character Control](#character-ontrol) 15 | - [Sound](#sound) 16 | - [Miscellaneous](#miscellaneous) 17 | 18 | ## Artificial Intelligence [](#table-of-contents) 19 | 20 | Name | Description | 2D | 3D 21 | :-- | :-- | --- | --- 22 | [`simplefollow.js`](AI/Scripts/simplefollow.js) | A very simple, flawed “follow the player’s transform” AI script. Because this uses Transform.Position, the object will simply pass through obstacles. Use script below for better results. | :white_check_mark: | :white_check_mark: 23 | [`simplechase.js`](AI/Scripts/simplechase.js) | A simple “follow the target” AI script using a Character Controller and applied forces. Collides with obstacles, but no logic for pathfinding yet. | :white_check_mark: | :white_check_mark: 24 | 25 | ## Animation [](#table-of-contents) 26 | 27 | ### Camera 28 | 29 | Name | Description | 2D | 3D 30 | :-- | :-- | --- | --- 31 | [`smoothfollow2d.js`](Camera/smoothfollow2d.js) | A two-axis smooth follow camera script, can be used for (X,Z) or (X,Y) movement. | :white_check_mark: | :white_check_mark: 32 | [FreeFlightCamera.js](Camera/FreeFlightCamera.js) | Fly through the scene using WSAD (or arrows) and mouse. | | :white_check_mark: 33 | 34 | ### Character Control 35 | 36 | Name | Description | 2D | 3D 37 | :-- | :-- | --- | --- 38 | [`topdowncontrols.js`](Character Control/topdowncontrols.js) | A script used to control the 3D Character Controller script, configured for use in top-down gameplay. | | :white_check_mark: 39 | [`sidescrollcontrols.js`](Character Control/sidescrollcontrols.js) | A script used to control the 3D Character Controller script, configured for use in sidescrolling gameplay. | | :white_check_mark: 40 | 41 | ## Sound [](#table-of-contents) 42 | 43 | ### Miscellaneous 44 | 45 | Name | Description | 2D | 3D 46 | :-- | :-- | --- | --- 47 | [`generateobjects.js`](Misc/generateobjects.js) | A simple script for generating a large number of objects on load. | :white_check_mark: | :white_check_mark: 48 | [`randomsizeonload.js`](Misc/randomsizeonload.js) | Simple script (often used in tandem with [`generateobjects.js`](Misc/generateobjects.js)) that randomly sizes/places object on awake. | :white_check_mark: | :white_check_mark: 49 | [`destroytaggedobjects.js`](Misc/destroytaggedobjects.js) | Simple “destroy object on collision if tagged” script. | :white_check_mark: | :white_check_mark: 50 | [`fadeinout.js`](Misc/fadeinout.js) | Simple fade in/fade out and load a level script. | :white_check_mark: | :white_check_mark: 51 | -------------------------------------------------------------------------------- /unity-awesomeness.sublime-project: -------------------------------------------------------------------------------- 1 | { 2 | "folders": 3 | [ 4 | { 5 | "path": "." 6 | } 7 | ] 8 | } 9 | --------------------------------------------------------------------------------