/// <summary> /// This will set <see cref="Doors"/> and it will modify tilemap and set doors into correct places /// </summary> /// <param name="doorLocations"></param> public void SetDoors(DoorLocation doorLocations) { Doors = doorLocations; var floorTile = TilemapHelper.GetTile(TilemapHelper.TileType.TilemapGround); var wallTile = TilemapHelper.GetTile(TilemapHelper.TileType.TilemapWall); // TODO: There might be more efficient method to do this // Clear doors Tilemap.SetTile(new Vector3Int(9, 9, 0), wallTile); Tilemap.SetTile(new Vector3Int(17, 5, 0), wallTile); Tilemap.SetTile(new Vector3Int(9, 0, 0), wallTile); Tilemap.SetTile(new Vector3Int(0, 5, 0), wallTile); // If room has top door if (Doors.HasFlag(Room.DoorLocation.Top)) { Tilemap.SetTile(new Vector3Int(9, 9, 0), floorTile); } // If room has right door if (Doors.HasFlag(Room.DoorLocation.Right)) { Tilemap.SetTile(new Vector3Int(17, 5, 0), floorTile); } // If room has bottom door if (Doors.HasFlag(Room.DoorLocation.Bottom)) { Tilemap.SetTile(new Vector3Int(9, 0, 0), floorTile); } // If room has left door if (Doors.HasFlag(Room.DoorLocation.Left)) { Tilemap.SetTile(new Vector3Int(0, 5, 0), floorTile); } }
public static void StartSwish(DoorLocation location) { if (location == DoorLocation.Store) { storeInstance.StartCoroutine(storeInstance.DoSwish()); } else if (location == DoorLocation.Home) { homeInstance.StartCoroutine(homeInstance.DoSwish()); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Ray ray = new Ray(animator.transform.position, animator.transform.forward); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.transform.CompareTag("Building")) { location = hitInfo.transform.GetComponent <DoorLocation>(); door = location.ReturnDoor(); setDestination(door.transform.position); } else { setDestination(hitInfo.transform.position); } } }
IEnumerator CoUpdate() { myTrans = this.transform; //baseYPosition = myTrans.localPosition.y; myItems = this.GetComponent<PlayerItems>(); controller = this.GetComponent<CharacterController>(); Physics.IgnoreLayerCollision( 30, 31 ); while(true) { if(grabbedItem || pauseMovement) { //Do nothing. } else { //Useable Item if(Input.GetKeyDown(KeyCode.Space)) { if(currentUseableItem != null) { currentUseableItem.startLocation = myTrans; currentUseableItem.Activate(); } } //Movement pressedDirection = DoorLocation.None; moveDirection = Vector3.zero; if(Input.GetKey(KeyCode.D)) { moveDirection += new Vector3(movementCheck, 0, 0); pressedDirection = DoorLocation.Right; } if(Input.GetKey(KeyCode.A)) { moveDirection += new Vector3(-movementCheck, 0, 0); pressedDirection = DoorLocation.Left; } if(Input.GetKey(KeyCode.S)) { moveDirection += new Vector3(0, 0, -movementCheck); pressedDirection = DoorLocation.Down; } if(Input.GetKey(KeyCode.W)) { moveDirection += new Vector3(0, 0, movementCheck); pressedDirection = DoorLocation.Up; } if(moveDirection == Vector3.zero) pressedDirection = DoorLocation.None; preMovement = moveDirection; moveDirection = transform.TransformDirection(moveDirection); float tempMovementMod = 0; if(myStats.MovementSpeed < 5) tempMovementMod = movementSpeedModifier/1.3f; else tempMovementMod = movementSpeedModifier/1.5f; moveDirection *= myStats.MovementSpeed*movementSpeedModifier; if(canAttack) { //Handling Movement Animations if(Input.GetKey(KeyCode.UpArrow)) { lastKeyPress = KeyCode.UpArrow; Shoot(Vector3.forward); } else if(Input.GetKey(KeyCode.DownArrow)) { lastKeyPress = KeyCode.DownArrow; Shoot(Vector3.back); } else if(Input.GetKey(KeyCode.LeftArrow)) { lastKeyPress = KeyCode.LeftArrow; Shoot(Vector3.left); } else if(Input.GetKey(KeyCode.RightArrow)) { lastKeyPress = KeyCode.RightArrow; Shoot(Vector3.right); } switch(lastKeyPress) { case KeyCode.UpArrow: if(moveDirection.magnitude > 0.1f) player.Play("BackWalking"); else player.Play("BackIdle"); break; case KeyCode.DownArrow: if(moveDirection.magnitude > 0.1f) player.Play("ForwardWalking"); else player.Play("ForwardIdle"); break; case KeyCode.LeftArrow: if(moveDirection.magnitude > 0.1f) { if(usingGun) player.Play("SideGunWalking"); else player.Play("SideWalking"); } else { if(usingGun) player.Play("SideGunIdle"); else player.Play("SideIdle"); } faceDirection.localRotation = Quaternion.Euler(0, -90, -90); break; case KeyCode.RightArrow: if(moveDirection.magnitude > 0.1f) { if(usingGun) player.Play("SideGunWalking"); else player.Play("SideWalking"); } else { if(usingGun) player.Play("SideGunIdle"); else player.Play("SideIdle"); } faceDirection.localRotation = Quaternion.Euler(0, 90, 90); break; } } myTrans.localPosition = new Vector3(myTrans.localPosition.x, baseYPosition, myTrans.localPosition.z); myTrans.localPosition += new Vector3(0, myTrans.localPosition.z*zOffset, 0); controller.height = 32; controller.height += myTrans.localPosition.z*zOffset; controller.Move(moveDirection * Time.deltaTime); } yield return new WaitForSeconds(0.01f); } }