// Start is called before the first frame update void Awake() { pathKeeper = this.GetComponent <PathKeeper>(); // if (TerrainGen.instance == null) { instance = this; } mapGenState = MapGen.none; hexGrid = new HexGrid(gridX, gridZ); edgeHexes = new List <Vector2Int>(); noiseMaps = new NoiseMap[2]; noiseMaps[0] = new NoiseMap() { scale = 2, weight = 30, offSet = new Vector2Int(Random.Range(0, 1000), Random.Range(0, 1000)) }; CalcNoise(noiseMaps[0]); noiseMaps[1] = new NoiseMap() { scale = 15, weight = 20, offSet = new Vector2Int(Random.Range(0, 1000), Random.Range(0, 1000)) }; CalcNoise(noiseMaps[1]); navMesh.buildHeightMesh = true; }
// Use this for initialization void Start() { player = GameObject.Find("Player"); playerKeeper = player.GetComponent <PathKeeper>(); playerController = GameObject.Find("TouchControlHandler").GetComponent <PlayerController>(); }
// Use this for initialization protected override void Start() { base.Start(); keeper = GetComponent <PathKeeper>(); target = GameObject.Find("Player"); targetDamageable = target.GetComponent <IDamageable>(); targetKeeper = target.GetComponent <PathKeeper>(); rb = GetComponent <Rigidbody>(); weapon = transform.Find("SwordPivotEnemy").gameObject; movement = GetComponent <GroundMovement>(); }
// Use this for initialization protected override void Start() { base.Start(); keeper = GetComponent <PathKeeper>(); target = GameObject.Find("Player"); targetDamageable = target.GetComponent <IDamageable>(); targetKeeper = target.GetComponent <PathKeeper>(); rb = GetComponent <Rigidbody>(); movement = GetComponent <AirMovement>(); anim = GetComponentInChildren <Animator>(); }
// Use this for initialization void Start() { rb = gameObject.GetComponent <Rigidbody>(); joint = gameObject.GetComponent <ConfigurableJoint>(); collider = gameObject.GetComponent <Collider>(); feetPosition = new Vector3(0, (-collider.bounds.extents.y) * .9f, 0); colliderHeight = collider.bounds.extents.y; colliderRadius = collider.bounds.extents.z; keeper = GetComponent <PathKeeper>(); runDirection = 0; verticalDirection = 0; invertDir = 1f; }
// Use this for initialization protected override void Start() { base.Start(); keeper = GetComponent <PathKeeper>(); target = GameObject.Find("Player"); targetDamageable = target.GetComponent <IDamageable>(); targetKeeper = target.GetComponent <PathKeeper>(); rb = GetComponent <Rigidbody>(); movement = GetComponent <GroundMovement>(); anim = transform.Find("BlobBoiModel").GetComponent <Animator>(); anim.SetFloat("RunBlend", 0f); }
// Use this for initialization void Start() { //haetaan kaikki tarvittavat komponentit rb = GetComponent <Rigidbody>(); healthSystem = GetComponent <HealthSystem>(); healthSystem.dieHandler = OnDie; keeper = GetComponent <PathKeeper>(); cameraTarget = GameObject.Find("CameraTarget"); movement = GetComponent <GroundMovement>(); movement.OnHitGround = OnHitGround; anim = transform.Find("PlayerModel").GetComponent <Animator>(); damageBlinker = GetComponent <MaterialBlinker>(); footStepHandler = transform.Find("PlayerModel").GetComponent <FootstepHandler>(); footStepHandler.FootStepHandler = Footstep; //animaatiot anim.SetFloat("RunBlend", 0f); animBaseLayer = anim.GetLayerIndex("BaseLayer"); animFallLayer = anim.GetLayerIndex("FallLayer"); animHurtLayer = anim.GetLayerIndex("HurtLayer"); animJumpLayer = anim.GetLayerIndex("JumpLayer"); animLandingLayer = anim.GetLayerIndex("LandingLayer"); anim.GetBehaviour <AttackLayerScript>().OnSlashEndHandler = OnSlashEnd; swordHitbox.SetActive(false); //lataa pelaajan tilanne tallennuksesta GameData.Player playerData = GameDataManager.Instance.GameData.player; if (playerData.firstCheckPointReached) { //paikka, suunta ja polku transform.position = playerData.position.toVector3(); transform.rotation = playerData.rotation.toQuaternion(); keeper.currentSpline = GameObject.Find(playerData.pathName).GetComponent <BezierSpline>(); //health healthSystem.currentHealth = playerData.currentHealth; healthSystem.maxHealth = playerData.maxHealth; } //siirrä kamera pelaajan paikalle cmDefaultCamera = GameObject.FindGameObjectWithTag("CMDefaultCamera"); mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); if (cmDefaultCamera != null) { cmDefaultCamera.SetActive(false); mainCamera.SetActive(false); cmDefaultCamera.transform.position = transform.position; mainCamera.transform.position = transform.position; StartCoroutine(ActivateCameras()); } }
// Use this for initialization protected override void Start() { base.Start(); keeper = GetComponent <PathKeeper>(); target = GameObject.Find("Player"); targetDamageable = target.GetComponent <IDamageable>(); targetKeeper = target.GetComponent <PathKeeper>(); rb = GetComponent <Rigidbody>(); movement = GetComponent <GroundMovement>(); healthSystem = GetComponent <HealthSystem>(); healthSystem.dieHandler = OnDie; damageBlinker = GetComponent <MaterialBlinker>(); anim = GetComponentInChildren <Animator>(); anim.SetFloat("RunBlend", 0f); }
// Start is called before the first frame update void Awake() { generated = false; PathKeeper.pathKeeper = this; debugText = new GUIStyle(); terrainGen = this.GetComponent <TerrainGen>(); pathGrids = new Dictionary <PathType, PathNode[, ]>(); gridX = TerrainGen.gridX; gridZ = TerrainGen.gridZ; criticalUpdateNodes = new Dictionary <PathType, List <PathNode> >(); criticalUpdateNodes.Add(PathType.normal, new List <PathNode>()); updateNodes = new Dictionary <PathType, List <Vector2Int> >(); updateNodes.Add(PathType.normal, new List <Vector2Int>()); indexes = new Dictionary <PathType, int>(); indexes[PathType.flight] = 0; indexes[PathType.normal] = 0; checkOffSets = new Vector3Int[] { //Odd new Vector3Int(1, 0, 0), new Vector3Int(1, 0, -1), new Vector3Int(1, 0, 1), new Vector3Int(0, 0, -1), new Vector3Int(0, 0, 1), new Vector3Int(-1, 0, 0), //Even new Vector3Int(1, 0, 0), new Vector3Int(0, 0, -1), new Vector3Int(0, 0, 1), new Vector3Int(-1, 0, 0), new Vector3Int(-1, 0, -1), new Vector3Int(-1, 0, 1) }; walkCost = 3; climbCost = 7; dropCost = 5; gridShowing = PathType.none; }
// Update is called once per frame void FixedUpdate() { overButton = false; mousePos = GetMousePosition(); mousePos.z = -2; snapPos = mousePos; snapPos.z = 0; snapPos = MyMath.SnapToSub(subSnaps, snapPos); transform.position = mousePos; if (UIHits.Count > 0) { TriButton hitButton; ButtonClick clickButton; foreach (RaycastResult hit in UIHits) { if (hit.gameObject != null) { hitButton = hit.gameObject.GetComponent <TriButton>(); clickButton = hit.gameObject.GetComponent <ButtonClick>(); triMenu.ResetButtons(); if (hitButton != null) { overButton = true; hitButton.SetState(1); } if (clickButton != null) { overButton = true; } } } } UIHits = new List <RaycastResult>(); UIEvent = new PointerEventData(UIEventSystem); UIEvent.position = Input.mousePosition; UICaster.Raycast(UIEvent, UIHits); if (selectedBuilding == null && selectedSpawner == null && !keepDetails) { triMenu.DestroyDetails(); } if (UIHits.Count > 0) { //Debug.Log("UI hit"); TriButton hitButton; LinkToggle linkButton; foreach (RaycastResult hit in UIHits) { //Check For TriMenu hitButton = hit.gameObject.GetComponent <TriButton>(); if (hitButton != null) { // Load details for whichever button hit. Vector2 detailPos = GetScreenPosition(hexHook.transform.position); detailPos.x -= 120; string buttonVal = hitButton.getValue().ToLower(); switch (buttonVal) { case "build_speed_augment_button": case "build_range_augment_button": case "build_damage_augment_button": case "build_chain_augment_button": case "build_fork_augment_button": case "build_multi_augment_button": case "build_ethereal_augment_button": triMenu.DestroyDetails(); triMenu.CreateDetails(detailPos); triMenu.AddDetail(hitButton.getValue(), -1); triMenu.LoadDetails(Towers.instance.GetAugment(buttonVal.Replace("build_", "").Replace("_button", "").Replace("_augment", ""))); triMenu.RefreshDetails(); keepDetails = true; break; case "build_fire_tower_button": case "build_water_tower_button": case "build_earth_tower_button": case "build_air_tower_button": case "build_basic_tower_button": triMenu.DestroyDetails(); triMenu.CreateDetails(detailPos); triMenu.AddDetail(Translator.Get(buttonVal), -1); string tower = buttonVal.Replace("build_", "").Replace("_button", "").Replace("_tower", ""); triMenu.LoadDetails(Towers.instance.GetTower(tower)); triMenu.RefreshDetails(); keepDetails = true; break; default: break; } if (lastButtonHover != buttonVal && triMenu.CurrentMenu() == "towers_build") { PreviewTowerRange(buttonVal.Replace("build_", "").Replace("_button", "").Replace("_tower", "")); } lastButtonHover = buttonVal; } //Check For Link Toggle linkButton = hit.gameObject.GetComponent <LinkToggle>(); if (linkButton != null) { Vector2 detailPos = GetScreenPosition(hexHook.transform.position); detailPos.x -= 96; } } } if (Input.GetAxis("Jump") == 1) { if (currentCamera == CurrentCamera.main) { ChangeCamera(CurrentCamera.overhead); } } else { ChangeCamera(CurrentCamera.main); } if (mouseCheck[0] == 1) { if (UIHits.Count > 0) { MenuPositioner dragHandle; foreach (RaycastResult UIhit in UIHits) { dragHandle = UIhit.gameObject.GetComponent <MenuPositioner>(); if (dragHandle != null) { dragHandle.StartDrag(); dragging = true; } } } } //Check left mouse button up; if (mouseCheck[0] == -1) { dragging = false; Ray ray; if (currentCamera == CurrentCamera.main) { ray = gameCam.ScreenPointToRay(Input.mousePosition); } else { ray = overHeadCam.ScreenPointToRay(Input.mousePosition); } RaycastHit hit; if (UIHits.Count > 0) { TriButton hitButton; ButtonClick clickButton; foreach (RaycastResult UIhit in UIHits) { hitButton = UIhit.gameObject.GetComponent <TriButton>(); clickButton = UIhit.gameObject.GetComponent <ButtonClick>(); if (hitButton != null) { string buttonValue = hitButton.getValue().ToLower(); TowerTypes towerType = TowerTypes.none; AugmentTypes augmentType = AugmentTypes.none; BuildingType buildingType = BuildingType.none; buttonValue = buttonValue.Replace("_button", ""); if (buttonValue.Contains("build_")) { buttonValue = buttonValue.Replace("build_", ""); if (buttonValue.Contains("_tower")) { buttonValue = buttonValue.Replace("_tower", ""); towerType = TowerBase.GetTowerType(buttonValue); } else if (buttonValue.Contains("_augment")) { buttonValue = buttonValue.Replace("_augment", ""); augmentType = Towers.GetAugmentType(buttonValue); } } MobSpawner spawner; switch (buttonValue) { case "path": PathKeeper.indexes[PathType.normal]++; PathKeeper.pathKeeper.FindGoal(PathType.normal, TerrainGen.GetGridPosition2D(PathKeeper.goal), TerrainGen.GetGridPosition2D(hexHook.transform.position)); break; case "select": TerrainGen.mapGenState = MapGen.pathing; buildingType = BuildingType.Base; break; case "regen": TerrainGen.instance.KillTerrain(); TerrainGen.mapGenState = MapGen.terrain; break; case "towers": triMenu.DestroyMenu(); triMenu.CreateMenu("towers_build"); break; case "augments": triMenu.DestroyMenu(); triMenu.CreateMenu("augments"); break; case "buildings": triMenu.DestroyMenu(); triMenu.CreateMenu("buildings"); break; case "sell": if (selectedBuilding != null) { float value = selectedBuilding.Sell(); value *= 0.8f; player.GiveGold((int)value); TowerBase.UpdateTowerHexes(); triMenu.DestroyMenu(); hexHook.SetActive(false); HexHighlighter.ResetGrid(); } break; case "upgrade": if (selectedBuilding != null) { if (player.hasGold(100)) { player.TakeGold(100); selectedBuilding.AddValue(100); selectedBuilding.GetComponent <TowerBase>().LevelUp(); triMenu.CreateDetails(); triMenu.LoadDetails(selectedBuilding.GetComponent <TowerBase>().GetDetails()); triMenu.RefreshDetails(); } } break; case "points": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.wavePoints *= 1.1f; CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "more": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.spawnNumber += 1; CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "less": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.spawnNumber -= 1; if (spawner.spawnNumber < 0) { spawner.spawnNumber = 0; } CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "faster": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.coolDownTime -= 1; if (spawner.coolDownTime < 1) { spawner.coolDownTime = 1; } CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "slower": spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (spawner != null) { spawner.coolDownTime += 1; CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } break; case "wall": buildingType = BuildingType.Wall; break; default: break; } int cost = Towers.instance.GetCost(buttonValue.Replace("build_", "").Replace("_button", "")); if (towerType != TowerTypes.none) { if (player.hasGold(cost)) { TowerBase towerBase = Instantiate(towerFabBasic, hexHook.transform.position, new Quaternion(), towerParent.transform) .GetComponent <TowerBase>(); player.TakeGold(cost); towerBase.SetProjectileParent(projectileParent); string tower = buttonValue.Replace("build_", "").Replace("_button", ""); towerBase.SetTower(TowerBase.GetTowerType(tower)); towerBase.UpdateLinks(); UpdateGrid(); CloseMenu(); // // // } } if (augmentType != AugmentTypes.none) { if (player.hasGold(cost)) { AugmentBase augmentBase = Instantiate(augmentFabBasic, hexHook.transform.position, new Quaternion(), towerParent.transform) .GetComponent <AugmentBase>(); player.TakeGold(cost); augmentBase.SetAugmentType(buttonValue); augmentBase.AddValue(cost); UpdateGrid(); CloseMenu(); } } if (buildingType != BuildingType.none) { if (player.hasGold(cost)) { if (buttonValue == "select") { buttonValue = "base"; } BuildingBase buildingBase = Instantiate(buildingFabBasic, hexHook.transform.position, new Quaternion(), towerParent.transform) .GetComponent <BuildingBase>(); buildingBase.SetBuilding(buttonValue); player.TakeGold(cost); UpdateGrid(hexHook.transform.position); CloseMenu(); } } } if (clickButton != null) { switch (clickButton.buttonClick) { case "pathing": if (HexHighlighter.showingType != GridType.path) { PathKeeper.ShowOnGrid(PathType.normal); HexHighlighter.showingType = GridType.path; } else { HexHighlighter.ResetGrid(); HexHighlighter.showingType = GridType.grid; } break; case "height": if (HexHighlighter.showingType != GridType.height) { HexHighlighter.ShowHeightMap(); HexHighlighter.showingType = GridType.height; } else { HexHighlighter.ResetGrid(); HexHighlighter.showingType = GridType.grid; } break; case "towerrange": if (HexHighlighter.showingType != GridType.range) { HexHighlighter.ResetGrid(); HexHighlighter.ShowTowersRange(true); HexHighlighter.showingType = GridType.range; } else { HexHighlighter.ResetGrid(); HexHighlighter.showingType = GridType.grid; } break; case "undock_details": triMenu.DockDetails(); break; } } } } else if (Physics.Raycast(ray, out hit, 10, UIMask)) { Debug.Log("Other Ui hits>"); LinkToggle hitToggle; hitToggle = hit.transform.parent.GetComponent <LinkToggle>(); if (hitToggle != null) { hitToggle.Toggle(); UpdateLinks(); showingRange = true; } } else { triMenu.DestroyMenu(); //Ray ray = gameCam.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction, Color.blue, 1); if (Physics.Raycast(ray, out hit)) { hexHook.SetActive(true); if (hit.transform.position != Vector3.zero) { PlaceHexHook(hit.transform.position); } else { PlaceHexHook(hit.point); } } BuildingBase buildingBase = null; if (hit.collider != null) { buildingBase = hit.transform.parent.GetComponent <BuildingBase>(); if (buildingBase != null) { triMenu.DestroyMenu(); Vector2 detailPos = GetScreenPosition(hexHook.transform.position); detailPos.x -= 120; triMenu.CreateMenu("towerselect"); triMenu.CreateDetails(detailPos); triMenu.LoadDetails(buildingBase.GetDetails()); triMenu.AddDetail("Upgrade Cost:", 100); triMenu.RefreshDetails(); selectedBuilding = buildingBase; selectedBuilding.UpdateLinks(); UpdateLinks(); //triMenu.DestroyButtons(); if (!showingRange && buildingBase is TowerBase towerBase) { towerBase.ShowHexes(); } } } Vector2 menuPos = GetScreenPosition(hexHook.transform.position); menuPos.x += 60; triMenu.transform.position = menuPos; // if (buildingBase == null) { selectedBuilding = null; HexHighlighter.ResetGrid(); hexHook.GetComponentInChildren <MeshRenderer>(true).gameObject.SetActive(false); MobSpawner spawner = MobSpawner.GetSpawner(TerrainGen.GetGridPosition2D(hexHook.transform.position)); if (TerrainGen.mapGenState == MapGen.terrainCon) { triMenu.CreateMenu("startmenu"); } else if (spawner == null) { triMenu.CreateMenu("base"); } else { CloseMenu(); triMenu.gameObject.SetActive(true); selectedSpawner = spawner; triMenu.CreateMenu("spawner"); triMenu.CreateDetails(); triMenu.LoadDetails(spawner.GetDetails()); triMenu.RefreshDetails(); } } else { hexHook.GetComponentInChildren <MeshRenderer>(true).gameObject.SetActive(true); } } mouseCheck[0] = 0; } if (mouseCheck[1] == -1) { if (!overButton) { if (rightClickTime <= 0.33f) { triMenu.DestroyMenu(); selectedBuilding = null; selectedSpawner = null; hexHook.SetActive(false); mouseCheck[1] = 0; lastButtonHover = null; HexHighlighter.ResetGrid(); showingRange = false; } } else if (overButton && !didBack) { if (triMenu.CurrentMenu() != "startmenu") { didBack = true; triMenu.DestroyMenu(); triMenu.CreateMenu("base"); } } } bool inX = !dragging && !overButton && Input.mousePosition.x > 0 - overBorder && Input.mousePosition.x < Screen.width + overBorder; bool inside = inX && Input.mousePosition.y > 0 - overBorder && Input.mousePosition.y < Screen.height + overBorder; if (inside) { MoveCamera(); } if (mouseCheck[1] == 1) { RotateCamera(); } if (triMenu.HaveLinks()) { triMenu.ReDrawLinks(); } }