Skip to content

Instantly share code, notes, and snippets.

View nastajus's full-sized avatar

Ian Nastajus nastajus

View GitHub Profile
@nastajus
nastajus / 0_reuse_code.js
Created June 3, 2014 14:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nastajus
nastajus / I_cannot_predicates_how_do_I_predicates.cs
Created June 3, 2014 16:24
how do I surpass this error? I don't understand what I'm doing wrong. Also tried simply Find(go) but nope to that also. error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
public void RemoveUserGO(GameObject go){
int i = UserCreatedGOs.FindIndex( obj => obj.GetInstanceID = go.GetInstanceID );
UserCreatedGOs.RemoveAt(i);
//...do more with i
}
@nastajus
nastajus / PlayerControl.cs
Created June 14, 2014 21:44
Was thinking of what data structure I'd procedurally populate the Input manager for Unity, came up with the following. But interestingly I first tried using enum Directions instead simply containing Up, Down, Left, and Right, but when I got to making the nested dictionary I realized that wouldn't help, that each player needs a **different** set …
public class PlayerControl : MonoBehaviour {
//...
private class Directions{
KeyCode Up;
KeyCode Down;
KeyCode Left;
KeyCode Right;
}
@nastajus
nastajus / GameLogic.cs
Created June 14, 2014 22:46
does the compiler optimize code like declarations in loops? seems lines 6, 7 are taken care of by what Dante/Zack told me before, to not worry about. Then what about redundant if statements inside my foreach loop lines 14, 15, which are only intended for initialization only. I bet THAT is wasteful, that the compiler wouldn't remove that. The com…
void Update(){
//constantly check player positions..
//find furthest apart X, Y
//adjust camera accordingly
Vector2 min;
Vector2 max;
//ASK ZACK: what's best way to initalize this?
if ( PlayerGOs != null ) {
@nastajus
nastajus / SnakeBody_shakes_uncontrollably.cs
Created June 15, 2014 12:57
the snake body shakes uncontrollably when it's close to it's target it's rotating to. Not sure how to approach this problem next. vid here: http://youtu.be/rTrsRnpJ0to
using UnityEngine;
using System.Collections;
public class SnakeBody : MonoBehaviour {
private float moveSpeed = 5f;
private float rotationSpeed = 10f;
private Transform target;
private Transform source;
@nastajus
nastajus / unity_power_touch.cs
Created June 23, 2014 01:02
what differences are there between these?
public class PowerupTouch : MonoBehaviour {
void OnTriggerEnter(Collider other){
GetComponent<MeshRenderer>().material.color = Color.green;
transform.renderer.material.color = Color.blue;
}
}
@nastajus
nastajus / CoroutineCounter.cs
Last active August 29, 2015 14:03
Had difficulties implementing Coroutines per this site http://unitypatterns.com/introduction-to-coroutines/ I can't figure out the cause of the problem. I've tried restarting Unity and rebooting my PC. I've tried passing string and method names. Nothing ever changes. I'm always consistently getting either 1 Hello when yield comes before Debug.Lo…
using UnityEngine;
using System.Collections;
public class CoroutineCounter : MonoBehaviour {
// Use this for initialization
void Start () {
//StartCoroutine("CountSeconds"); //works
StartCoroutine("SayHelloEveryFrame"); //doesn't work
@nastajus
nastajus / Zack_recursion_groups.cs
Created July 15, 2014 00:08
Orbit-like over simplification of groups to teach me recursion at my request.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
* Polymorphism practice. Doing exercises selected by Zack for me.
* http://tutorials.csharp-online.net/Inheritance_and_Polymorphism%E2%80%94Exercises
*
@nastajus
nastajus / control_move.cs
Created July 29, 2014 22:51
probably lame lane movement.
[RequireComponent(typeof(CharacterController))]
public class MyController : MonoBehaviour
{
enum Lane { left, middle, right };
Lane curLane = Lane.middle;
CharacterController cc;
void Start () {