Thursday, August 7, 2014

Design Guidelines

40Analysis

30% Design

20% Code

10% Test

UNITY: Key press & one step movement control

Vector3 pos;

void Start () {
}

void Update () {

float veloc = 0.1f;

if(Input.GetKeyDown(KeyCode.LeftArrow))
{
pos = new Vector3(veloc * -1,0,0);
}
else if(Input.GetKeyDown(KeyCode.RightArrow))
{
pos = new Vector3(veloc,0,0);
}
else if(Input.GetKeyDown(KeyCode.UpArrow))
{
pos = new Vector3(0,veloc,0);
}
else if(Input.GetKeyDown (KeyCode.DownArrow))
{
pos = new Vector3(0,veloc * -1,0);
}

transform.localPosition += pos;
pos = new Vector3(0,0,0);
}

UNITY: Key pressed movement control

====================== VERSION 1 ======================

Vector3 pos;

void Start () {
}

void Update ()
{
float veloc = 0.1f;

if(Input.GetKey(KeyCode.LeftArrow))
{
pos = new Vector3(veloc * -1,0,0);
}
else if(Input.GetKey(KeyCode.RightArrow))
{
pos = new Vector3(veloc,0,0);
}
else if(Input.GetKey(KeyCode.UpArrow))
{
pos = new Vector3(0,veloc,0);
}
else if(Input.GetKey(KeyCode.DownArrow))
{
pos = new Vector3(0,veloc * -1,0);
}

transform.localPosition += pos;
pos = new Vector3(0,0,0);
}

====================== VERSION 2 ======================

void Start () {
}

void Update ()
{
if(Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(-1,0,0);
}
if(Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(1,0,0);
}
if(Input.GetKey(KeyCode.UpArrow))
{
transform.Translate(0,1,0);
}
if(Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(0,-1,0);
}

====================== VERSION 3 ======================

Vector3 pos;

void Start () {
}

void Update ()
{
if(Input.GetKey(KeyCode.LeftArrow))
{
pos.x--;
}
else if(Input.GetKey(KeyCode.RightArrow))
{
pos.x++;
}
else if(Input.GetKey(KeyCode.UpArrow))
{
pos.y++;
}
else if(Input.GetKey(KeyCode.DownArrow))
{
pos.y--;
}

transform.localPosition += pos;
pos = new Vector3(0,0,0);
}

====================== VERSION 4 ======================

Vector3 pos;
void Start () {
}

void Update () 
{
if(Input.GetKey(KeyCode.LeftArrow))
pos.x-=.1f;
}
else if(Input.GetKey(KeyCode.RightArrow))
pos.x+=.1f;
}
else if(Input.GetKey(KeyCode.UpArrow))
pos.y+=.1f;
}
else if(Input.GetKey(KeyCode.DownArrow))
pos.y-=.1f;
}

transform.localPosition += pos;
pos = new Vector3(0,0,0);
}

====================== VERSION 5 ======================

public float velocidadDespzamiento;

void Start () {
}

void Update ()
{
velocidadDespzamiento = .1f;

if (Input.GetKey(KeyCode.UpArrow))
{
this.transform.Translate(Vector3.forward * velocidadDespzamiento);
}

if (Input.GetKey(KeyCode.DownArrow))
{
this.transform.Translate(Vector3.back * velocidadDespzamiento);
}

if (Input.GetKey(KeyCode.LeftArrow))
{
this.transform.Translate(Vector3.left * velocidadDespzamiento);
}

if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(Vector3.right * velocidadDespzamiento);
}

if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(Vector3.right * velocidadDespzamiento);
}
}

====================== VERSION 6 ======================

Vector3 pos;
float veloc = 0f;
bool inCollision = false;

void Start () {
}

void Update ()
{
veloc = 0.01f;

if(Input.GetKey(KeyCode.RightArrow))
{
pos = new Vector3(veloc,0,0);
}
if(Input.GetKey(KeyCode.UpArrow))
{
pos = new Vector3(0,veloc,0);
}
if(Input.GetKey(KeyCode.LeftArrow))
{
pos = new Vector3(veloc * -1,0,0);
}
if(Input.GetKey(KeyCode.DownArrow))
{
pos = new Vector3(0,veloc * -1,0);
}

GetComponent<Transform> ().localPosition += pos;
pos = new Vector3 (0,0,0);
GetComponent<Transform> ().localRotation = Quaternion.identity;
}