//Players //0 = Null //1 = 1 //2 = 2 //Duh!.. //Blocks //0 = Nothing //1 = Ship part //2 = Destroyed ship part //3 = Splash // Use this for initialization /*void GetStats () { * GameObject statsCarrier = GameObject.Find ("StatsCarrier"); * if (statsCarrier) { * stats = statsCarrier.GetComponent<StatsCarrier>(); * aiAmount = stats.aiAmount; * shipAmount = stats.shipAmount; * size = stats.size; * } * }*/ void Start() { //GetStats (); if (aiAmount == 1) { ai = (NormalAI)gameObject.AddComponent("NormalAI"); ai.aiPlayer = 2; } if (aiAmount == 2) { NormalAI ai = (NormalAI)gameObject.AddComponent("NormalAI"); ai.aiPlayer = 2; ai = (NormalAI)gameObject.AddComponent("NormalAI"); ai.aiPlayer = 1; } center = size / 2; activePlayer = 1; shipIndex = new int[2]; battlefieldGenerated = new bool[2]; shipsLeft = new int[2]; coordinates = new int[3, (int)size.x, (int)size.y, (int)size.z]; blocksPos = new Vector3[3, Mathf.RoundToInt(size.x * size.y * size.z)]; blocks = new GameObject[3, blocksPos.Length]; shipBlocks = new GameObject[3, blocksPos.Length]; battlefieldGenerated[activePlayer - 1] = true; bcol = GetComponent <BoxCollider>(); GenerateBattlefield(activePlayer); shipIndex[0] = shipAmount; shipIndex[1] = shipAmount; Camera.main.transform.position = center + new Vector3(0, 0, -size.z * 2); }
// Update is called once per frame void Update() { healthbar.transform.localScale = new Vector3(health / 100.0f, healthbar.transform.localScale.y, healthbar.transform.localScale.z); if (outside && Input.GetKeyDown(KeyCode.Escape)) { //Go to main menu SceneManager.LoadScene("MainMenu"); } if (Input.GetKeyDown(KeyCode.R)) { //Go to main menu SceneManager.LoadScene("Main Scene"); } if (!outside && Input.GetKeyDown(KeyCode.Escape)) { //Pause menu if (Time.timeScale == 1) { Time.timeScale = 0; resumeButton.gameObject.SetActive(true); mainMenuButton.gameObject.SetActive(true); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } else { Time.timeScale = 1; resumeButton.gameObject.SetActive(false); mainMenuButton.gameObject.SetActive(false); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } } if (health <= 0) { death(); } if (!dead && !hanging && !isReading) { CharacterController controller = GetComponent <CharacterController> (); if (controller.isGrounded) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= currentSpeed / 3f; if (Input.GetButtonDown("Jump") && !sneaking && !crouching) { moveDirection.y = jumpSpeed; } } moveDirection.y -= gravity * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); // Set animations here //Walking if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) { anim.SetBool("Walking", true); } else if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.W)) { anim.SetBool("Walking", false); } //Backward Walking if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)) { anim.SetBool("Backward Walk", true); isBackwards = true; } else if (Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.S)) { anim.SetBool("Backward Walk", false); isBackwards = false; } //Running if (Input.GetKeyDown(KeyCode.LeftShift) && !crouching && !sneaking) { anim.SetBool("Running", true); isRunning = true; currentSpeed = runSpeed; } else if (Input.GetKeyUp(KeyCode.LeftShift) && !crouching && !sneaking) { anim.SetBool("Running", false); isRunning = false; currentSpeed = walkSpeed; } //Left Strafe if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) { anim.SetBool("Left Strafe", true); isStrafing = true; } else if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.A)) { anim.SetBool("Left Strafe", false); isStrafing = false; } //Right Strafe if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) { anim.SetBool("Right Strafe", true); isStrafing = true; } else if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.D)) { anim.SetBool("Right Strafe", false); isStrafing = false; } //Jump if (Input.GetKeyDown(KeyCode.Space) && !sneaking && !crouching) { anim.SetBool("Jump", true); } else if (Input.GetKeyUp(KeyCode.Space) && !sneaking && !crouching) { anim.SetBool("Jump", false); } //Crouch if (Input.GetKeyDown(KeyCode.C) && !sneaking) { if (!crouching) { crouching = true; anim.SetBool("Crouch", true); anim.SetBool("Running", false); currentSpeed = crouchSpeed; controller.center = new Vector3(0f, 0.63f, 0f); controller.height = 1.1f; } else if (crouching && canStand) { crouching = false; currentSpeed = walkSpeed; anim.SetBool("Crouch", false); controller.center = new Vector3(0f, 0.94f, 0f);; controller.height = 1.733011f; } } //Sneaking if (Input.GetKeyDown(KeyCode.V) && !isRunning && !isStrafing && !isBackwards && !crouching) { sneaking = true; anim.SetBool("Sneak", true); currentSpeed = sneakSpeed; } else if (Input.GetKeyUp(KeyCode.V) && !isRunning && !isStrafing && !isBackwards && !crouching) { sneaking = false; anim.SetBool("Sneak", false); currentSpeed = walkSpeed; } //Punching if (Input.GetMouseButtonDown(0) && canPunch) { canPunch = false; Invoke("resetPunch", 1); Invoke("resetPunchAnim", 0.1f); anim.SetBool("Punch", true); Physics.Raycast(punchCast.transform.position, punchCast.transform.forward, out hit, 0.75f); Debug.DrawRay(punchCast.transform.position, punchCast.transform.forward * 0.75f, Color.green); try{ if (hit.collider.tag == "Enemy") { NormalAI nai = hit.collider.gameObject.GetComponent <NormalAI>(); nai.TakeDamage(); } } catch { } } } if (!dead && hanging) { animsFalse(); //change controlls to drop, get up, or left and right anim.SetBool("Hang Up", false); anim.SetBool("Hang Down", false); CharacterController controller = GetComponent <CharacterController> (); moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= currentSpeed / 5f; controller.Move(moveDirection * Time.deltaTime); //Left Strafe if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) { anim.SetBool("Hang Left", true); } else if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.A)) { anim.SetBool("Hang Left", false); } //Right Strafe if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) { anim.SetBool("Hang Right", true); } else if (Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.D)) { anim.SetBool("Hang Right", false); } //Climb Down if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) { anim.SetBool("Hang Down", true); anim.SetBool("Hanging", false); anim.SetBool("Hang Right", false); anim.SetBool("Hang Left", false); whd.stopRaycasting(); hanging = false; } } if (Input.GetMouseButtonUp(1) && inNote1) { readNote = !readNote; isReading = !isReading; Note1Pic.gameObject.SetActive(readNote); } if (Input.GetMouseButtonUp(1) && inNote2) { readNote = !readNote; isReading = !isReading; Note2Pic.gameObject.SetActive(readNote); } if (Input.GetMouseButtonUp(1) && switchTrigger) { moveDoor = true; promptText.text = ""; } if (Input.GetMouseButtonUp(1) && inDoor1) { switchDoor21 = true; promptText.text = ""; } if (Input.GetMouseButtonUp(1) && inDoor2) { switchDoor22 = true; promptText.text = ""; } if (moveDoor) { firstDoor.transform.position = Vector3.MoveTowards(firstDoor.transform.position, new Vector3(firstDoor.transform.position.x, 15, firstDoor.transform.position.z), 1 * Time.deltaTime); } if (switchDoor21 && switchDoor22) { secondDoor.transform.position = Vector3.MoveTowards(firstDoor.transform.position, new Vector3(firstDoor.transform.position.x, 10, firstDoor.transform.position.z), 1 * Time.deltaTime); } }