Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public class PlayerController : MonoBehaviour {
- int rotNum; //in case I would ever need to know what cardinal direction the player is facing.
- bool canMove = true;
- bool currentlyInteracting = false;
- float speed = 5.0f;
- bool isAxisInUse = false;
- Vector3 pos;
- GameObject dialogue;
- GameObject dialogueText;
- string[] allLines = File.ReadAllLines(@"C:\Users\Public\Documents\Unity Projects\Dungeon-Crawler\Script.txt");
- // Use this for initialization
- void Start () {
- rotNum = 0;
- pos = transform.position;
- //dialogue = GameObject.Find("Dialogue");
- //dialogueText = dialogue.transform.GetChild(3).gameObject;
- //dialogue.SetActive(false);
- }
- // Update is called once per frame
- void Update () {
- if (canMove == true) {
- //Movement Code
- if (Input.GetAxis("Horizontal") > 0) {
- if(isAxisInUse == false) {
- transform.Rotate(0,90,0);
- if (rotNum == 3) {
- rotNum = 0;
- }else {
- rotNum++;
- }
- isAxisInUse = true;
- Debug.Log("rotNum = " + rotNum);
- }
- }
- if (Input.GetAxis("Horizontal") < 0) {
- if (isAxisInUse == false) {
- transform.Rotate(0,-90,0);
- if (rotNum == 0) {
- rotNum = 3;
- }else {
- rotNum--;
- }
- isAxisInUse = true;
- Debug.Log("rotNum = " + rotNum);
- }
- }
- if (Input.GetAxis("Horizontal") == 0) {
- isAxisInUse = false;
- }
- if (Input.GetKeyDown(KeyCode.W)) {
- bool disableMove = false;
- RaycastHit hit;
- if (Physics.Raycast(transform.position, transform.forward, out hit, 1.0f)) {
- if(hit.collider.gameObject.tag == "Wall") {
- disableMove = true;
- Debug.Log("Hit a Wall");
- }else {
- disableMove = false;
- }
- }
- if (disableMove == false) {
- pos += transform.forward;
- }
- }
- if (Input.GetKeyDown(KeyCode.S)) {
- bool disableMove = false;
- RaycastHit hit;
- if (Physics.Raycast(transform.position, (transform.forward * -1), out hit, 1.0f)) {
- if(hit.collider.gameObject.tag == "Wall") {
- disableMove = true;
- Debug.Log("Hit a Wall");
- }else {
- disableMove = false;
- }
- }
- if (disableMove == false) {
- pos += transform.forward * -1;
- }
- }
- if (Input.GetKeyDown(KeyCode.Q)) {
- bool disableMove = false;
- RaycastHit hit;
- if (Physics.Raycast(transform.position, (transform.right * -1), out hit, 1.0f)) {
- if(hit.collider.gameObject.tag == "Wall") {
- disableMove = true;
- Debug.Log("Hit a Wall");
- }else {
- disableMove = false;
- }
- }
- if (disableMove == false) {
- pos += transform.right * -1;
- }
- }
- if (Input.GetKeyDown(KeyCode.E)) {
- bool disableMove = false;
- RaycastHit hit;
- Debug.DrawRay(transform.position, Vector3.forward, Color.green, 1.0f);
- if (Physics.Raycast(transform.position, transform.right, out hit, 1.0f)) {
- if(hit.collider.gameObject.tag == "Wall") {
- disableMove = true;
- Debug.Log("Hit a Wall");
- }else {
- disableMove = false;
- }
- }
- if (disableMove == false) {
- pos += transform.right;
- }
- }
- transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
- }
- //Interaction Code
- if (Input.GetKeyDown(KeyCode.Space) && currentlyInteracting == false) {
- RaycastHit hit;
- if (Physics.Raycast(transform.position, transform.forward, out hit, 1.0f)) {
- if(hit.collider.gameObject.tag == "Character") {
- currentlyInteracting = true;
- StartDialogue();
- DialogueLines(allLines, 0, 5);
- currentlyInteracting = false;
- }
- }
- }
- }
- void StartDialogue() {
- Debug.Log("Starting Dialogue");
- canMove = false;
- //dialogue.SetActive(true);
- }
- void DialogueLines(string[] lines, int startLine, int endLine) {
- Debug.Log("Reading DialogueLines");
- int counter = startLine;
- string curLine = "";
- if (Input.GetKeyDown(KeyCode.Space)) {
- curLine = lines[counter];
- Debug.Log(counter);
- counter++;
- }
- if (counter == endLine) {
- Debug.Log("Ending Dialogue.");
- canMove = true;
- dialogue.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement