Skip to content

Instantly share code, notes, and snippets.

View ahmadnaser's full-sized avatar

Ahmad Naser ahmadnaser

View GitHub Profile
@ahmadnaser
ahmadnaser / gist:43f1520faa295162a5f7f6120177ca12
Last active October 14, 2016 18:59
Timer In C# and Unity
using UnityEngine;
using System.Collections;
/// <summary>
/// Descending Timer.
/// </summary>
public class Timer : MonoBehaviour
{
public string startTime = "";
public float delayTime = 1;
public void ActivateOptionsMenu(){
RectTransform Canvas = GameObject.Find ("OptionsCanvas").GetComponent<RectTransform> ();
if (Canvas != null) {
RectTransform[] recs = Canvas.GetComponentsInChildren<RectTransform> (true);
int Count = 0;
int NumOfElements = 2;
foreach (RectTransform r in recs) {
if (r.gameObject.name == "Overly") {
@ahmadnaser
ahmadnaser / SingletonService In Unity
Created October 8, 2016 18:42
Create single instance in unity
using UnityEngine;
using System;
using System.Collections.Generic;
public static class SingletonService {
private static Dictionary<Type, object> _singletons = new Dictionary<Type, object>();
//Adds a singleton to the manager
public static void RegisterSingletonInstance<T>(T instance) where T : class {
@ahmadnaser
ahmadnaser / Bootstrap Default Template By AhmadNaser
Created April 19, 2016 23:11
Bootstrap Default Template By AhmadNaser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap Template By AhmadNaser</title>
<!-- Bootstrap -->
@ahmadnaser
ahmadnaser / get the char as an output of two array of bytes summation
Created March 12, 2016 23:46
get the char as an output of two array of bytes summation
//convert string to array of chars
string text = "abcd";
char[] array2 = text.ToCharArray();
//1-convert char to array of bytes
//2-sumation of two array of bytes
//3-return the value of the two arays as array of chars
//4-get the char as an output of two array of bytes summation
//For More Information visit: http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0600
using UnityEngine;
using System.Collections;
public class LevelLoader : MonoBehaviour
{
public int calculations = 10000;
public int iterations = 10000;
public bool inAwake = true;
public bool inStart = true;
@ahmadnaser
ahmadnaser / PlayerKeyboardController
Created December 29, 2015 09:17
Allow player to move and jump based on keyboard arrows and space jump
using UnityEngine;
using System.Collections;
public class PlayerKeyboardController : MonoBehaviour
{
//to make movement more smoother
//Change Mass to 0.1f
//Linear Drag to 0.4f
@ahmadnaser
ahmadnaser / Joystick.cs for mobile buttons
Created December 29, 2015 07:07
add Right,Left,Jump Capabilities for UI buttons in UNITY
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Joystick : MonoBehaviour, IPointerUpHandler, IPointerDownHandler {
private PlayerJoystick playerjoystick;
public GameObject Player;
private float force = 300;
void Start() {
@ahmadnaser
ahmadnaser / PlayerSmoothFollow.cs
Created December 29, 2015 07:02
Allow Camera to Smart smooth follow the player attached to main camera
using UnityEngine;
using System.Collections;
public class PlayerSmoothFollow : MonoBehaviour {
[SerializeField] private Transform target = null;
[SerializeField] private float distance = 20f;
[SerializeField] private float height = 5f;
[SerializeField] private float damping = 5f;
[SerializeField] private bool smoothRotation = true;
@ahmadnaser
ahmadnaser / PlayerJoystick.cs
Created December 29, 2015 06:57
Allow player to move based on three buttons - left,right,jump
using UnityEngine;
using System.Collections;
public class PlayerJoystick : MonoBehaviour
{
public float speed = 0.1f, maxVelocity = 0.05f;
private Rigidbody2D myBody;
private Animator anim;
private bool moveLeft, moveRight;