├── Editor Scripts ├── readme.md ├── InstantPathMovementEditor.cs ├── CheckpointManagerEditor.cs ├── SmoothPathMovementEditor.cs └── GameManagerEditor.cs ├── LICENSE ├── Hover ├── Ground.prefab ├── Hoverer.prefab ├── Ground.prefab.meta ├── Hoverer.prefab.meta ├── Hover.cs.meta ├── HeightFromGround.cs.meta ├── HeightFromGround.cs └── Hover.cs ├── ObjectPooling ├── CubePrefab.prefab ├── ShooterPrefab.prefab ├── CubePrefab.prefab.meta ├── ShooterPrefab.prefab.meta ├── Bullet.cs.meta ├── MoveForward.cs.meta ├── ObjectPooling.cs.meta ├── Bullet.cs ├── MoveForward.cs └── ObjectPooling.cs ├── DestroyOffscreen.cs ├── CheckpointScript.cs ├── GameManager.cs ├── UrlButton.cs ├── GoalScript.cs ├── KillOnTouch.cs ├── OscillatingMovement.cs ├── InstantiateAtClick.cs ├── Draggable.cs ├── Cursor2D.cs ├── CheckpointManager.cs ├── GotoLevel.cs ├── FlagManager.cs ├── MoveToPoint.cs ├── IntervalSpawner.cs ├── PlatformerMovement.cs ├── LookAtMouse.cs ├── Readme.md ├── TriggerAreaLookAtTag.cs ├── Script List.txt ├── DualStickController.cs ├── SmoothPathMovement.cs └── InstantPathMovement.cs /Editor Scripts/readme.md: -------------------------------------------------------------------------------- 1 | Test 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ...do whatever you want with my code 2 | if you like it, say something :) 3 | -------------------------------------------------------------------------------- /Hover/Ground.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mouseroot/Unity3D-Scripts/HEAD/Hover/Ground.prefab -------------------------------------------------------------------------------- /Hover/Hoverer.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mouseroot/Unity3D-Scripts/HEAD/Hover/Hoverer.prefab -------------------------------------------------------------------------------- /ObjectPooling/CubePrefab.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mouseroot/Unity3D-Scripts/HEAD/ObjectPooling/CubePrefab.prefab -------------------------------------------------------------------------------- /ObjectPooling/ShooterPrefab.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mouseroot/Unity3D-Scripts/HEAD/ObjectPooling/ShooterPrefab.prefab -------------------------------------------------------------------------------- /Hover/Ground.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 801937ba6ff70404da22504884928c09 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Hover/Hoverer.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d4ea7d688c935340b28dcb2c6acc415 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /ObjectPooling/CubePrefab.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26f402ca5dc520042bdf9561868f8724 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /ObjectPooling/ShooterPrefab.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b89cea52c6719f4099ac78ce7732706 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Hover/Hover.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df0677e14cfab0549b52557b5c522a23 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /ObjectPooling/Bullet.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca6803e40954ddd438b176505634df95 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Hover/HeightFromGround.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f6605abcdc1bf6d46b111499999e97fc 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /ObjectPooling/MoveForward.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7efdac3de5231b54b8adc2a3965d4b53 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /ObjectPooling/ObjectPooling.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 117d3004eec0d7c4c89f042111b1dbe8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /DestroyOffscreen.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class DestroyOffscreen : MonoBehaviour { 5 | 6 | // Update is called once per frame 7 | void Update () { 8 | if (renderer.isVisible == false) 9 | { 10 | Destroy(gameObject); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CheckpointScript.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [RequireComponent(typeof(BoxCollider))] 5 | public class CheckpointScript : MonoBehaviour { 6 | public bool checkpointActivated = false; 7 | 8 | public void OnTriggerEnter(Collider other) 9 | { 10 | checkpointActivated = true; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GameManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | public class GameManager : MonoBehaviour { 5 | 6 | public List gameObjects= new List(); 7 | 8 | // Use this for initialization 9 | void Start () { 10 | } 11 | 12 | // Update is called once per frame 13 | void Update () { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /UrlButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [RequireComponent(typeof(Collider))] 5 | [RequireComponent(typeof(Rigidbody))] 6 | 7 | public class UrlButton : MonoBehaviour { 8 | 9 | public string URL; 10 | 11 | // Update is called once per frame 12 | void OnMouseUpAsButton() { 13 | Application.OpenURL(URL); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ObjectPooling/Bullet.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Bullet : MonoBehaviour { 5 | 6 | public float lifetime = 3; 7 | 8 | 9 | // Deactivates the object after "lifetime" seconds 10 | void OnEnable(){ // Note: OnEnable 11 | Invoke("deactivate",lifetime); 12 | } 13 | 14 | void deactivate(){ 15 | this.gameObject.SetActive(false); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ObjectPooling/MoveForward.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class MoveForward : MonoBehaviour { 5 | // Moves the bullet forward 6 | // 7 | // This script can be replaced without breaking the 8 | // object pooling mechanism 9 | 10 | public float speed = 20f; 11 | void Update(){ 12 | transform.position = new Vector3(0f,0f,transform.position.z+speed*Time.deltaTime); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /GoalScript.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class GoalScript : MonoBehaviour { 5 | 6 | // Use this for initialization 7 | void Start () { 8 | 9 | } 10 | 11 | // Update is called once per frame 12 | void Update () { 13 | 14 | } 15 | 16 | void OnTriggerEnter(Collider col) { 17 | int currentLevel = Application.loadedLevel; 18 | Application.LoadLevel(currentLevel + 1); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /KillOnTouch.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class KillOnTouch : MonoBehaviour { 5 | 6 | // Use this for initialization 7 | void Start () { 8 | 9 | } 10 | 11 | // Update is called once per frame 12 | void Update () { 13 | 14 | } 15 | 16 | void OnCollisionEnter(Collision col) { 17 | int loadedLevel = Application.loadedLevel; 18 | Application.LoadLevel(loadedLevel); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Hover/HeightFromGround.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class HeightFromGround : MonoBehaviour { 5 | public LayerMask ground; 6 | void Awake(){ 7 | if(ground == null) 8 | ground = LayerMask.NameToLayer("Ground"); 9 | } 10 | public float getHeight(){ 11 | float distanceToGround = -1; 12 | RaycastHit hit; 13 | if (Physics.Raycast(transform.position, -Vector3.up, out hit,Mathf.Infinity,ground)) 14 | distanceToGround = hit.distance; 15 | return distanceToGround; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /OscillatingMovement.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | class OscillatingMovement : MonoBehaviour 6 | { 7 | [Range(-1.00f,1.00f)] 8 | public float directionX = 0f; 9 | [Range(-1.00f,1.00f)] 10 | public float directionY = 0f; 11 | 12 | private float index = 0f; 13 | 14 | void Update() 15 | { 16 | index += Time.deltaTime; 17 | float x = directionX * Mathf.Cos(1.0f * index); 18 | float y = directionY * Mathf.Sin(1.0f * index); 19 | transform.localPosition = new Vector3(transform.position.x + x, transform.position.y + y, 0); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /InstantiateAtClick.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class InstantiateAtClick : MonoBehaviour { 5 | 6 | private Ray ray; 7 | private Vector3 origin; 8 | 9 | public GameObject objectToCreate; 10 | public int zIndex = 0; 11 | 12 | // Update is called once per frame 13 | void Update () { 14 | if (Input.GetMouseButtonUp(0)) 15 | { 16 | ray = Camera.main.ScreenPointToRay(Input.mousePosition); 17 | origin = ray.origin; 18 | origin.z = zIndex; 19 | ray.origin = origin; 20 | Instantiate(objectToCreate, origin, transform.rotation); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Draggable.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [RequireComponent(typeof(BoxCollider))] 5 | 6 | public class Draggable : MonoBehaviour { 7 | 8 | private Ray ray; 9 | private Vector3 origin; 10 | 11 | public bool lockX = true; 12 | public bool lockY = true; 13 | public int zIndex = 0; 14 | 15 | void OnMouseDrag() 16 | { 17 | ray = Camera.main.ScreenPointToRay(Input.mousePosition); 18 | origin = ray.origin; 19 | origin.z = zIndex; 20 | if (lockX) 21 | { 22 | origin.y = transform.position.y; 23 | } 24 | if (lockY) 25 | { 26 | origin.x = transform.position.x; 27 | } 28 | ray.origin = origin; 29 | transform.position = ray.origin; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Cursor2D.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Cursor2D : MonoBehaviour { 5 | 6 | private Ray ray; 7 | private Vector3 origin; 8 | private Vector3 currentPosition; 9 | 10 | public Texture2D cursorGraphic; 11 | public bool showMouse = true; 12 | // Use this for initialization 13 | void Start () { 14 | Screen.showCursor = showMouse; 15 | transform.gameObject.renderer.material.mainTexture = cursorGraphic; 16 | } 17 | 18 | // Update is called once per frame 19 | void Update () { 20 | currentPosition = transform.position; 21 | ray = Camera.main.ScreenPointToRay(Input.mousePosition); 22 | origin = ray.origin; 23 | currentPosition.x = origin.x; 24 | currentPosition.y = origin.y; 25 | transform.position = currentPosition; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CheckpointManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | public class CheckpointManager : MonoBehaviour { 5 | 6 | public List checkpoints = new List(); 7 | public bool allCheckpointsActivated = false; 8 | 9 | // Use this for initialization 10 | void Start () { 11 | 12 | } 13 | 14 | // Update is called once per frame 15 | void Update () { 16 | int totalCheckpoints = checkpoints.Count; 17 | int activatedCheckpoints = 0; 18 | foreach (GameObject checkpoint in checkpoints) 19 | { 20 | if (checkpoint.GetComponent().checkpointActivated) 21 | { 22 | activatedCheckpoints++; 23 | } 24 | } 25 | if (activatedCheckpoints == totalCheckpoints) 26 | { 27 | allCheckpointsActivated = true; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /GotoLevel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class GotoLevel : MonoBehaviour { 5 | 6 | public string levelName; 7 | 8 | public enum TriggerCondition 9 | { 10 | Return, 11 | Click 12 | } 13 | 14 | public TriggerCondition changeOn; 15 | 16 | // Use this for initialization 17 | void Start () { 18 | 19 | } 20 | 21 | // Update is called once per frame 22 | void Update () { 23 | if (changeOn == TriggerCondition.Return) 24 | { 25 | if (Input.GetKey(KeyCode.Return)) 26 | { 27 | Application.LoadLevel(levelName); 28 | } 29 | } 30 | else if (changeOn == TriggerCondition.Click) 31 | { 32 | if (Input.GetMouseButton(0)) 33 | { 34 | Application.LoadLevel(levelName); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Editor Scripts/InstantPathMovementEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | [CanEditMultipleObjects] 5 | [CustomEditor(typeof(InstantPathMovement))] 6 | public class InstantPathMovementEditor : Editor { 7 | 8 | private InstantPathMovement iPathMovement; 9 | 10 | public override void OnInspectorGUI() 11 | { 12 | iPathMovement = (InstantPathMovement)target; 13 | base.OnInspectorGUI(); 14 | } 15 | 16 | public void OnSceneGUI() 17 | { 18 | foreach (PathNode node in iPathMovement.pathNodes) 19 | { 20 | node.pathPosition = Handles.FreeMoveHandle(node.pathPosition, Quaternion.identity, 0.3f, Vector3.zero, Handles.DrawRectangle); 21 | } 22 | } 23 | Tool LastTool = Tool.None; 24 | 25 | void OnEnable() 26 | { 27 | LastTool = Tools.current; 28 | Tools.current = Tool.None; 29 | } 30 | 31 | void OnDisable() 32 | { 33 | Tools.current = LastTool; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Hover/Hover.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | [RequireComponent (typeof (Rigidbody))] 4 | [RequireComponent (typeof (HeightFromGround))] 5 | 6 | public class Hover : MonoBehaviour { 7 | 8 | public float hoverHeight = 10f; 9 | public float acceleration = 10f; 10 | public float drag = .5f; 11 | 12 | private HeightFromGround height; 13 | private Rigidbody rigidbody; 14 | 15 | void Awake(){ 16 | height = this.gameObject.GetComponent(); 17 | rigidbody = this.gameObject.GetComponent(); 18 | rigidbody.drag = drag; 19 | } 20 | 21 | void FixedUpdate(){ 22 | float distanceFromGround = height.getHeight(); 23 | float magnitude; 24 | if(hoverHeight>distanceFromGround) {magnitude = (9.8f*rigidbody.mass) + acceleration;} 25 | else {magnitude = (9.8f*rigidbody.mass) - acceleration;} 26 | //rigidbody.AddRelativeForce(Vector3.up*(hoverHeight-distanceFromGround+(9.8f*rigidbody.mass))); 27 | rigidbody.AddRelativeForce(Vector3.up*magnitude); 28 | } 29 | } -------------------------------------------------------------------------------- /Editor Scripts/CheckpointManagerEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | [CanEditMultipleObjects] 6 | [CustomEditor(typeof(CheckpointManager))] 7 | public class CheckpointManagerEditor : Editor { 8 | 9 | private CheckpointManager checkpointManager; 10 | 11 | public override void OnInspectorGUI() 12 | { 13 | checkpointManager = (CheckpointManager)target; 14 | 15 | base.OnInspectorGUI(); 16 | } 17 | 18 | public void OnSceneGUI() 19 | { 20 | Handles.Label(checkpointManager.transform.position, "Checkpoint Manager"); 21 | foreach (GameObject checkpoint in checkpointManager.checkpoints) 22 | { 23 | checkpoint.transform.position = Handles.FreeMoveHandle(checkpoint.transform.position, Quaternion.identity, 0.4f, Vector3.zero, Handles.DrawRectangle); 24 | Handles.Label(checkpoint.transform.position - new Vector3(0, 0.45f, 0f), checkpoint.transform.name); 25 | Handles.DrawLine(checkpointManager.transform.position, checkpoint.transform.position); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /FlagManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Collections; 5 | 6 | [Serializable] 7 | public class Flag 8 | { 9 | public string flagName; 10 | public bool flagValue = false; 11 | } 12 | 13 | public class FlagManager : MonoBehaviour { 14 | 15 | public Flag[] gameFlags; 16 | 17 | public void OnDrawGizmosSelected() 18 | { 19 | Handles.color = Color.white; 20 | Handles.Label(transform.position,"FlagManager (" + gameFlags.Length + " Flags)"); 21 | } 22 | 23 | public void createFlag(string name,bool setValue) 24 | { 25 | Flag newFlag = new Flag(); 26 | newFlag.flagName = name; 27 | newFlag.flagValue = setValue; 28 | gameFlags[gameFlags.Length] = newFlag; 29 | 30 | } 31 | 32 | public bool getFlag(string name) 33 | { 34 | foreach(Flag flag in gameFlags) 35 | { 36 | if(flag.flagName == name) 37 | { 38 | return flag.flagValue; 39 | } 40 | } 41 | return false; 42 | } 43 | 44 | public void setFlag(string name,bool val) 45 | { 46 | foreach(Flag flag in gameFlags) 47 | { 48 | if(flag.flagName == name) 49 | { 50 | flag.flagValue = val; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /MoveToPoint.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | public class MovetoPoint : MonoBehaviour { 6 | 7 | public Vector3 point; 8 | public float duration; 9 | public enum MoveType 10 | { 11 | EaseIn, 12 | EaseOut, 13 | Instant 14 | 15 | } 16 | public MoveType moveType; 17 | private float startTime; 18 | 19 | // Use this for initialization 20 | void Start () { 21 | startTime = Time.time; 22 | } 23 | 24 | // Update is called once per frame 25 | void Update () { 26 | if (moveType == MoveType.EaseIn) 27 | { 28 | transform.position = Vector3.Lerp(transform.position, point, (Time.time - startTime) / duration); 29 | } 30 | else if (moveType == MoveType.EaseOut) 31 | { 32 | transform.position = Vector3.MoveTowards(transform.position, point, (Time.time - startTime) / duration); 33 | } 34 | else if (moveType == MoveType.Instant) 35 | { 36 | transform.position = point; 37 | } 38 | } 39 | 40 | public void OnDrawGizmosSelected() 41 | { 42 | Gizmos.DrawLine(transform.position, point); 43 | Gizmos.color = Color.red; 44 | Gizmos.DrawSphere(point, 0.06f); 45 | Handles.Label(point, " " + moveType.ToString() + "(" + duration + "s)"); 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /IntervalSpawner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | public class IntervalSpawner : MonoBehaviour { 6 | 7 | public enum SpawnChoice 8 | { 9 | All, 10 | Random 11 | } 12 | 13 | public float delayTime; 14 | public float spawnInterval; 15 | public float spawnSize; 16 | public GameObject[] spawnList; 17 | public SpawnChoice spawnType; 18 | 19 | // Use this for initialization 20 | void Start () { 21 | Invoke("spawnObject", delayTime); 22 | } 23 | 24 | // Update is called once per frame 25 | void Update () { 26 | 27 | } 28 | 29 | void OnDrawGizmos() 30 | { 31 | Gizmos.color = Color.white; 32 | Gizmos.DrawWireCube(transform.position, Vector3.one); 33 | } 34 | 35 | private void spawnObject() 36 | { 37 | Vector3 position = Vector3.zero; 38 | if (spawnType == SpawnChoice.All) 39 | { 40 | for (int i = 0; i < spawnList.Length; i++) 41 | { 42 | Instantiate(spawnList[i], position, transform.rotation); 43 | } 44 | } 45 | else if (spawnType == SpawnChoice.Random) 46 | { 47 | int listSize = spawnList.Length; 48 | int randomSel = Random.Range(0, listSize); 49 | Instantiate(spawnList[randomSel], position, transform.rotation); 50 | } 51 | Invoke("spawnObject", spawnInterval); 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Editor Scripts/SmoothPathMovementEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | [CanEditMultipleObjects] 5 | 6 | [CustomEditor(typeof(SmoothPathMovement))] 7 | public class SmoothPathMovementEditor : Editor { 8 | 9 | private SmoothPathMovement sPathMovement; 10 | private GUIStyle style; 11 | 12 | public override void OnInspectorGUI() 13 | { 14 | sPathMovement = (SmoothPathMovement)target; 15 | base.OnInspectorGUI(); 16 | } 17 | 18 | 19 | public void OnSceneGUI() 20 | { 21 | style = new GUIStyle(); 22 | Handles.BeginGUI(); 23 | if (sPathMovement.pathNodes.Length >= 1) 24 | { 25 | foreach (SmoothPathNode node in sPathMovement.pathNodes) 26 | { 27 | style.normal.textColor = node.textColor; 28 | node.pathPosition = Handles.FreeMoveHandle(node.pathPosition, Quaternion.identity, 0.2f, Vector3.zero, Handles.RectangleCap); 29 | Vector2 pos2D = HandleUtility.WorldToGUIPoint(node.pathPosition); 30 | Handles.Label(node.pathPosition, node.nodeName, style); 31 | } 32 | } 33 | Handles.EndGUI(); 34 | } 35 | Tool LastTool = Tool.None; 36 | 37 | void OnEnable() 38 | { 39 | LastTool = Tools.current; 40 | Tools.current = Tool.None; 41 | } 42 | 43 | void OnDisable() 44 | { 45 | Tools.current = LastTool; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /PlatformerMovement.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [RequireComponent(typeof(BoxCollider))] 5 | [RequireComponent(typeof(Rigidbody))] 6 | 7 | public class PlatformerMovement : MonoBehaviour { 8 | 9 | public float moveSpeed; 10 | public float jumpPower; 11 | public string platformTagString; 12 | 13 | private Rigidbody rBody; 14 | private bool onGround = false; 15 | 16 | 17 | // Use this for initialization 18 | void Start () { 19 | rBody = transform.GetComponent(); 20 | } 21 | 22 | // Update is called once per frame 23 | void Update () { 24 | 25 | if (Input.GetKey(KeyCode.LeftArrow)) 26 | { 27 | transform.Translate(Vector3.left * moveSpeed * Time.deltaTime); 28 | } 29 | else if (Input.GetKey(KeyCode.RightArrow)) 30 | { 31 | transform.Translate(Vector3.right * moveSpeed * Time.deltaTime); 32 | } 33 | if (Input.GetKey(KeyCode.Space) && onGround) 34 | { 35 | onGround = false; 36 | rBody.AddForce(Vector3.up * (jumpPower * 2)); 37 | } 38 | } 39 | 40 | void OnCollisionEnter(Collision other) 41 | { 42 | if (other.gameObject.transform.tag == platformTagString) 43 | { 44 | onGround = true; 45 | } 46 | } 47 | 48 | void OnCollisionStay(Collision other) 49 | { 50 | if (other.gameObject.transform.tag != platformTagString) 51 | { 52 | onGround = false; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /LookAtMouse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Script: LookAtMouse 3 | * 4 | * By: Mouseroot 5 | * 6 | * Perspective: 2D Only 7 | * 8 | * Useful for: Topdown shooters, Topdown click to move, Topdown etc etc... 9 | * 10 | * Description: Attaching this script to a sprite facing up (in 2d thats, exactly what it means) 11 | * the sprite will always look at the mouse by rotating at the center (the default) 12 | * 13 | * Todo: Could add an additional Lerp/Slerp function to create delayed rotation 14 | */ 15 | using UnityEngine; 16 | using System.Collections; 17 | 18 | public class LookAtMouse : MonoBehaviour 19 | { 20 | private float angle; 21 | private Vector3 mousePosition; 22 | private Vector3 lookPosition; 23 | private Ray ray; 24 | 25 | public void Update() 26 | { 27 | //Store mouse position 28 | mousePosition = Input.mousePosition; 29 | 30 | //Force 0 on the Z, since it doesnt matter in 2D 31 | mousePosition.z = 0; 32 | 33 | //Create a ray 34 | ray = Camera.main.ScreenPointToRay(Input.mousePosition); 35 | 36 | //Store the origin of the ray(essentialy where the mouse is) 37 | lookPosition = ray.origin; 38 | 39 | //Get a relative position 40 | lookPosition = lookPosition - transform.position; 41 | 42 | //Do some trig to get the corret angle (Found this formula online, long long ago so no source, but thx whoever came up with this) 43 | angle = Mathf.Atan2(lookPosition.x, lookPosition.y) * -Mathf.Rad2Deg; 44 | 45 | //Set the sprites rotation to the angle 46 | transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ObjectPooling/ObjectPooling.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | /* 6 | Object Pooling tutorial here 7 | https://www.youtube.com/watch?v=9-zDOJllPZ8 8 | 9 | IMPORTANT: The bullet prebab must have the bullet.cs script to work properly 10 | */ 11 | 12 | public class ObjectPooling : MonoBehaviour { 13 | 14 | public GameObject bullet;// The object to be pooled 15 | public int listSize = 0; // size of the pool 16 | public bool isListExpandable = true; // if more objects are required 17 | 18 | private List objectList; // the list to store the objects 19 | 20 | void Awake(){ 21 | objectList = new List(); 22 | // Initialise all the objects in the pool 23 | for(int i = 0; i < listSize; i++){ 24 | GameObject obj = (GameObject)Instantiate(bullet); 25 | obj.SetActive(false); 26 | objectList.Add(obj); 27 | } 28 | } 29 | 30 | // Change the update function to suit your game 31 | void Update(){ 32 | if(Input.GetButtonDown("Jump")){ 33 | Invoke("Fire",1f); 34 | } 35 | } 36 | 37 | // Instantiates the objects, it does not move the bullet 38 | public void Fire(){ 39 | bool isObjectAvailable = false; 40 | // Checks for an inactive gameobject and activates it 41 | foreach(GameObject temp in objectList){ 42 | if(!temp.activeInHierarchy){ 43 | isObjectAvailable = true; 44 | temp.transform.position = transform.position; 45 | temp.transform.rotation = transform.rotation; 46 | temp.SetActive(true); 47 | break; 48 | } 49 | } 50 | // if there is no active game object AND the list is expandable, 51 | // then expands the list 52 | if(!isObjectAvailable && isListExpandable){ 53 | GameObject obj = (GameObject)Instantiate(bullet); 54 | obj.transform.position = transform.position; 55 | obj.transform.rotation = transform.rotation; 56 | objectList.Add(obj); 57 | obj.SetActive(true); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Unity3D Scripts 2 | =============== 3 | 4 | Script|Description 5 | ----|----------- 6 | Cursor2D|Script that manages the visibility of the mouse cursor aswell as the image that that is used as the cursor 7 | Draggable|Script that allows any object to be dragged, also allows locking the X,Y axis 8 | GotoLevel|loads the specified level by clicking the mouse or hitting the return key 9 | InstantiateAtClick|creates the specified item at the 2D mouse location 10 | IntervalSpawner|spawns a collection of items either all at once or 1 randomly at a set interval 11 | LookAtMouse|Rotates the object to look at the mouse position 12 | PlatformerMovement|left,right and jump aswell as onGround checking to prevent excessive jumping 13 | UrlButton|script that opens a url when clicked 14 | FlagManager|script that handles global flags, flags being the binary true or false value 15 | OscillatingMovement|script that moves an object in an oscilating pattern 16 | InstantPathMovement|script that animates an object by settings its position to a set of positions instantly(no smooth animation) 17 | SmoothPathMovement|script that animates an object by transitioning from a set of positions smoothly (lerp,slerp,MoveTowards) 18 | MoveToPoint|EaseIn/Out or instant movement that animates to a set position 19 | GameManager/GameManagerEditor|Manages invisible but important background systems like score,health,inventory and anything else 20 | CheckpointManager/CheckpointScript|Script that manages all gameObjects that have the CheckpointScript, which tracks if the attached collider has been triggered 21 | DualStickController|Dual Stick (4 direction move/attack) controller that will make sprite face in whatever direction you are attacking 22 | TriggerAreaLookAtTag|Will track(rotate, lookat) object with tag when the object enters the trigger area and stop when object leaves (think, tower defense) 23 | DestroyOffscreen|Will destroy the gameobject when its no longer visible to the renderer 24 | -------------------------------------------------------------------------------- /TriggerAreaLookAtTag.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [RequireComponent(typeof(Rigidbody2D))] 5 | 6 | public class TriggerAreaLookAtTag : MonoBehaviour { 7 | 8 | public string trackingTag; 9 | private bool isTracking = false; 10 | private GameObject trackingObject; 11 | 12 | // Use this for initialization 13 | void Start () { 14 | 15 | } 16 | 17 | // Update is called once per frame 18 | void Update () { 19 | if (isTracking && trackingObject != null) 20 | { 21 | // (Yes this is from the LookAtMouse script) 22 | //Look at trackingObject 23 | Vector3 position = trackingObject.transform.position; 24 | 25 | //Force 0 on the Z, since it doesnt matter in 2D 26 | position.z = 0; 27 | 28 | //Get a relative position 29 | Vector3 lookPosition = position - transform.position; 30 | 31 | //Do some trig to get the corret angle (Found this formula online, long long ago so no source, but thx whoever came up with this) 32 | float angle = Mathf.Atan2(lookPosition.x, lookPosition.y) * -Mathf.Rad2Deg; 33 | 34 | //Set the sprites rotation to the angle 35 | transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); 36 | } 37 | } 38 | 39 | //When an object enters the area 40 | void OnTriggerEnter2D(Collider2D col) 41 | { 42 | if (col.gameObject.tag == trackingTag) 43 | { 44 | print("Tracking object " + col.gameObject.name); 45 | isTracking = true; 46 | trackingObject = col.gameObject; 47 | } 48 | } 49 | 50 | //When an object leaves the area 51 | void OnTriggerExit2D(Collider2D col) 52 | { 53 | if (col.gameObject.tag == trackingTag) 54 | { 55 | print("No longer tracking " + col.gameObject.name); 56 | isTracking = false; 57 | trackingObject = null; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Script List.txt: -------------------------------------------------------------------------------- 1 | Cursor2D 2 | - Script that manages the visibility of the mouse cursor aswell as the image that that is used as the cursor 3 | 4 | Draggable 5 | - Script that allows any object to be dragged, also allows locking the X,Y axis 6 | 7 | GotoLevel 8 | - loads the specified level by clicking the mouse or hitting the return key 9 | 10 | InstantiateAtClick 11 | - creates the specified item at the 2D mouse location 12 | 13 | IntervalSpawner 14 | - spawns a collection of items either all at once or 1 randomly at a set interval 15 | 16 | LookAtMouse 17 | - Rotates the object to look at the mouse position 18 | 19 | PlatformerMovement 20 | - left,right and jump aswell as onGround checking to prevent excessive jumping 21 | 22 | UrlButton 23 | - script that opens a url when clicked 24 | 25 | FlagManager 26 | - script that handles global flags, flags being the binary true or false value 27 | 28 | OscillatingMovement 29 | - script that moves an object in an oscilating pattern 30 | 31 | InstantPathMovement 32 | - script that animates an object by settings its position to a set of positions instantly(no smooth animation) 33 | 34 | SmoothPathMovement 35 | - script that animates an object by transitioning from a set of positions smoothly (lerp,slerp,MoveTowards) 36 | 37 | MoveToPoint 38 | - EaseIn/Out or instant movement that animates to a set position 39 | 40 | GameManager/GameManagerEditor 41 | - Manages invisible but important background systems like score,health,inventory and anything else 42 | 43 | CheckpointManager/CheckpointManagerEditor/CheckpointScript 44 | - Script that manages all gameObjects that have the CheckpointScript, which tracks if the attached collider has been triggered 45 | 46 | ObjectPooling - Implements the "object pooling" mechanism. See video https://www.youtube.com/watch?v=9-zDOJllPZ8 47 | Must be used with Bullet.cs 48 | 49 | Bullet - Deactivates the gameobject after a set time. Used in conjunction with ObjectPooling.cs 50 | 51 | MoveForward - Moves an object forward along z-axis 52 | 53 | 54 | -------------------------------------------------------------------------------- /Editor Scripts/GameManagerEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | using System.Collections.Generic; 4 | 5 | [CanEditMultipleObjects] 6 | [CustomEditor(typeof(GameManager))] 7 | public class GameManagerEditor : Editor { 8 | 9 | private bool showProperties = true; 10 | private Object newObject; 11 | private GameManager gameManager; 12 | private GameObject toBeRemoved; 13 | 14 | public void OnSceneGUI() 15 | { 16 | Handles.Label(gameManager.transform.position - new Vector3(0,0.11f,0f), "Game Manager"); 17 | Handles.color = Color.green; 18 | Handles.CubeCap(0, gameManager.transform.position, Quaternion.identity, 0.15f); 19 | foreach (GameObject gameObj in gameManager.gameObjects) 20 | { 21 | gameObj.transform.position = Handles.FreeMoveHandle(gameObj.transform.position, Quaternion.identity,0.3f,Vector3.zero,Handles.DrawRectangle); 22 | Handles.color = Color.white; 23 | Handles.Label(gameObj.transform.position - new Vector3(0,0.35f,0f), gameObj.transform.name); 24 | Handles.DrawLine(gameManager.transform.position,gameObj.transform.position); 25 | } 26 | } 27 | 28 | public override void OnInspectorGUI() 29 | { 30 | gameManager = (GameManager)target; 31 | EditorGUILayout.LabelField("Game Manager"); 32 | EditorGUILayout.Space(); 33 | 34 | EditorGUILayout.BeginHorizontal(); 35 | newObject = EditorGUILayout.ObjectField(newObject, typeof(Object)); 36 | if (GUILayout.Button("Add")) 37 | { 38 | gameManager.gameObjects.Add((GameObject)newObject); 39 | newObject = null; 40 | } 41 | EditorGUILayout.EndHorizontal(); 42 | 43 | showProperties = EditorGUILayout.Foldout(showProperties, "Managed Properties"); 44 | if (showProperties) 45 | { 46 | foreach (GameObject gameObj in gameManager.gameObjects) 47 | { 48 | EditorGUILayout.BeginHorizontal(); 49 | EditorGUILayout.LabelField(gameObj.transform.name); 50 | if (GUILayout.Button("Remove")) 51 | { 52 | toBeRemoved = gameObj; 53 | } 54 | EditorGUILayout.EndHorizontal(); 55 | } 56 | gameManager.gameObjects.Remove(toBeRemoved); 57 | toBeRemoved = null; 58 | } 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /DualStickController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class DualStickController : MonoBehaviour { 5 | 6 | public float moveSpeed = 1.5f; 7 | public float shootSpeed = 1f; 8 | public GameObject projectile; 9 | public float shootDelay = 0.5f; 10 | 11 | [Header("Extendable Options")] 12 | public GameObject[] _projectilePool; 13 | 14 | private Vector2 moveDirection; 15 | private Vector2 shootDirection; 16 | private Vector2 position; 17 | private bool canFireWeapon = true; 18 | 19 | //Enable the weapon 20 | void enableWeaponFire() 21 | { 22 | canFireWeapon = true; 23 | } 24 | 25 | //Disable the weapon 26 | void disableWeaponFire() 27 | { 28 | canFireWeapon = false; 29 | } 30 | 31 | // Use this for initialization 32 | void Start () { 33 | 34 | } 35 | 36 | // Update is called once per frame 37 | void Update () { 38 | 39 | //Get Vector2 direction of movement 40 | moveDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); 41 | 42 | //Convert Vector3 to Vector2 for 2D 43 | position = new Vector2(transform.position.x, transform.position.y); 44 | 45 | //Move by + * *