Skip to content

Instantly share code, notes, and snippets.

View estebanpadilla's full-sized avatar

Esteban Padilla estebanpadilla

View GitHub Profile
@estebanpadilla
estebanpadilla / Unity Raycast block on Update()
Last active December 20, 2015 06:29
Ray cast from object to detecting hit, draws a red line when a hit is detected otherwise draws a green light forward from object.
void Update () {
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, out hit, 10.0F)){
print("There is something in front of the object!");
Debug.DrawLine(transform.position, hit.collider.gameObject.transform.position, Color.red);
}
@estebanpadilla
estebanpadilla / Creates a coroutine block.
Created July 26, 2013 04:19
Creates a coroutine block. The execution of a coroutine can be paused at any point using the yield statement. The yield return value specifies when the coroutine is resumed. Coroutines are excellent when modelling behaviour over several frames. Coroutines have virtually no performance overhead. StartCoroutine function always returns immediately,…
void MyCoroutine() {
print("Starting " + Time.time);
StartCoroutine(StartCoroutine_MyCoroutine(time));
print("Before WaitAndPrint Finishes " + Time.time);
}
IEnumerator StartCoroutine_MyCoroutine(float waitTime) {
yield return new WaitForSeconds(waitTime);
print("WaitAndPrint " + Time.time);
}
@estebanpadilla
estebanpadilla / AutoSnap.cs
Last active April 10, 2021 21:27
Auto snap to grid in Unity If you need to auto snap a gameObject to the grid in unity this script will help you. Usage: Create a Editor folder in your assets folder. Add the AutoSnap.cs script to the Editor folder. To open press Command + L (Mal), Control + L (PC) Source: http://answers.unity3d.com/questions/148812/is-there-a-toggle-for-snap-to-…
using UnityEngine;
using UnityEditor;
public class AutoSnap : EditorWindow
{
private Vector3 prevPosition;
private bool doSnap = true;
private float snapValue = 1;
[MenuItem( "Edit/Auto Snap %_l" )]
@estebanpadilla
estebanpadilla / gist:6401118
Created August 31, 2013 22:44
Method for Unity to get angle using a start and end points. Code can be improve.
private float GetAngleFromPosition(float x1, float y1, float x2, float y2){
float o = 0;
float a = 0;
bool doingA = false;
bool doingB = false;
bool doingC = false;
bool doingD = false;
if(x1 >= x2 && y1 <= y2){//set for A
o = x1 - x2;
@estebanpadilla
estebanpadilla / gist:6401133
Created August 31, 2013 22:45
Some methods to get positions using angle and radius.
private float Sine(float angle){
float sin = Mathf.Sin((Mathf.PI / 180)* angle);
return sin;
}
private float Cosine(float angle){
float cosine = Mathf.Cos((Mathf.PI / 180) * angle);
return cosine;
}
@estebanpadilla
estebanpadilla / gist:6401141
Created August 31, 2013 22:48
Initial class script for Unity.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
// File: #SCRIPTNAME#
// Project:
// Description:
// Author:Esteban Padilla
// Email:
// Copyright (C) 2013, (R). All rights reserved.