Created
September 20, 2016 20:40
-
-
Save sabotai/7d25549279260ef37e14ee068375972a to your computer and use it in GitHub Desktop.
GD205 Week 4 In-Class
This file contains hidden or 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; | |
using System.Collections; | |
public class MoveWKey : MonoBehaviour { | |
public GameObject textThing; | |
bool hasKey; | |
public GameObject key; | |
public GameObject winSpot; | |
public Vector3[] verboten; | |
public GameObject[] enemies; | |
Vector3 startPos; | |
// Use this for initialization | |
void Start () { | |
hasKey = false; | |
startPos = new Vector3 (0,0,0); | |
transform.position = startPos; //set the initial players position | |
textThing.GetComponent<TextMesh> ().text = "You are in the starting position."; | |
} | |
// Update is called once per frame | |
void Update () { | |
if (Input.GetKeyDown ("up")) { | |
Debug.Log ("Someone just pressed up."); | |
transform.position += new Vector3(0,0,1); | |
} | |
if (Input.GetKeyDown ("down")) { | |
transform.position += new Vector3(0,0,-1); | |
} | |
if (Input.GetKeyDown ("left")) { | |
transform.position += new Vector3(-1,0,0); | |
} | |
if (Input.GetKeyDown ("right")) { | |
transform.position += new Vector3(1,0,0); | |
} | |
//textThing.GetComponent<TextMesh> ().text = "You are in pos (" + transform.position.x + ", "+ transform.position.z + ")"; | |
if (transform.position == key.transform.position) { | |
Debug.Log ("found key"); | |
hasKey = true; | |
} | |
if (transform.position == winSpot.transform.position) { | |
if (hasKey) { | |
textThing.GetComponent<TextMesh> ().text = "you win"; | |
} else { | |
textThing.GetComponent<TextMesh> ().text = "cube locked :("; | |
} | |
} | |
//lets check the players position against all the forbidden positions | |
for (int i = 0; i < verboten.Length; i++){ | |
//if the player position is the same as any of the positions in the list (cycled with i)... | |
if (transform.position == verboten [i]) { | |
//send a console message saying "you ded" | |
Debug.Log ("you ded"); | |
//reset the players position to whatever startPos is | |
transform.position = startPos; | |
hasKey = false; | |
} | |
} | |
//lets check the players position against all the enemy positions | |
for (int i = 0; i < enemies.Length; i++){ | |
enemies [i].transform.position += new Vector3 (1, 0, 0); | |
//if the player position is the same as any of the positions in the list (cycled with i)... | |
if (transform.position == enemies[i].transform.position) { | |
//send a console message saying "you ded" | |
Debug.Log ("enemy gotcha"); | |
//reset the players position to whatever startPos is | |
transform.position = startPos; | |
hasKey = false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment