This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[RequireComponent(typeof(SpriteRenderer))] | |
public class SpriteWrapper : MonoBehaviour { | |
[Header("Sprite Wrapper")] | |
[Tooltip("Should sprite be wrapped when reaching the edge of the screen?"), SerializeField] | |
private bool wrap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gradually changes a value towards a desired goal over time - implemented from Unity C# | |
*/ | |
public func smoothDamp(current c: CGFloat, target t: CGFloat, currentVelocity: inout CGFloat, smoothTime time: CGFloat, maxSpeed: CGFloat = CGFloat.infinity, deltaTime: CGFloat) -> CGFloat { | |
let smoothTime = max(0.0001, time) | |
let num = 2 / smoothTime | |
let num2 = num * deltaTime | |
let num3 = 1 / (1 + num2 + 0.48 * num2 * num2 + 0.235 * num2 * num2 * num2) | |
var num4 = c - t | |
let num5 = t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
convenience init?(size: CGSize, color: UIColor) { | |
// Create a rect for this context | |
var rect = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height) | |
// Generate the texture | |
// Start image context with the given size | |
UIGraphicsBeginImageContext(size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using UnityEngine; | |
[RequireComponent(typeof(BoxCollider2D))] | |
public class CharacterController2D : MonoBehaviour | |
{ | |
#region Fields and Properties | |
[Range(.001f, 0.3f)] | |
public float SkinWidth = .02f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
import SceneKit | |
import QuartzCore | |
class MyViewController : UIViewController | |
{ | |
override func viewDidLoad() | |
{ | |
super.viewDidLoad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGFloat) randomNumberBetween0and1 | |
{ | |
// Generates a random float between 0.0f and 1.0f. Remember to seed using | |
// srandom(time(0)); | |
return random() / (float)0x7fffffff; | |
} |