void ShootArrow() { GameObject playerObject = CurrentLevelVariableManagement.GetPlayerReference(); float preHeading = attachedCharacterInput.GetActualClass().GetFacingDirection() == 1 ? 0 : 180; //Apparently there is some issue with the bow's position when attached to the player object, because it is always (0, 0, 0). This fixes it. GameObject instantiatedArrow = (GameObject)(Instantiate(arrow, attachedCharacterInput.GetActualClass().gameObject.transform.position + new Vector3(1.2f, 0, 0) * attachedCharacterInput.GetActualClass().GetFacingDirection(), Quaternion.identity)); ProjectileScript instantiatedArrowScript = instantiatedArrow.GetComponent <ProjectileScript> (); Vector3 positionToFireToward; float accuracy; if (attackPlayer) { positionToFireToward = playerObject.transform.position; accuracy = 30; } else { Vector3 shootDirection; shootDirection = Input.mousePosition; shootDirection.z = 0.0f; shootDirection = Camera.main.ScreenToWorldPoint(shootDirection); shootDirection = shootDirection - transform.position; positionToFireToward = shootDirection; accuracy = 0; } instantiatedArrowScript.InitializeProjectileWithThresholdAndDeviation(positionToFireToward, 12, preHeading, 30, accuracy, attackPowerStrength); }
//Required to initialize. public void StartPlayerDistanceChecking() { player = CurrentLevelVariableManagement.GetPlayerReference().transform; mainParticleSystem = GetComponent <ParticleSystem> (); //Start the coroutine. StartCoroutine(ActivityIsDependentOnPlayerDistance()); }
//Set references to the playerIcon, start necessary coroutines, etc. void InitializeNPCPanelController() { playerTransform = CurrentLevelVariableManagement.GetPlayerReference().transform; playerIcon = transform.Find("FlippingItem").Find("Character").Find("Head").GetComponent <SpriteRenderer> ().sprite; mainSpeechControl = CurrentLevelVariableManagement.GetLevelUIReference().transform.Find("Speech Bubble").GetComponent <SpeechControl> (); mainInteractablePanelController = CurrentLevelVariableManagement.GetLevelUIReference().transform.Find("InteractablePanels").gameObject.GetComponent <InteractablePanelController> (); StartCoroutine("CheckForAndAttemptToSpeakToPlayer"); }
protected override void InitializeCharacter() { //Set required variables for the enemy to function. player = CurrentLevelVariableManagement.GetPlayerReference().transform; InitializeEnemy(); enemyControlCoroutine = EnemyControl(); StartCoroutine(enemyControlCoroutine); }
//Look into initializing this once the player comes into activation distance. protected virtual void InitializeHealthBar() { player = CurrentLevelVariableManagement.GetPlayerReference().transform; currentHealth = lifePoints; //Create panel uiHealthController = CurrentLevelVariableManagement.GetLevelUIReference().transform.Find("Health Controller").gameObject.GetComponent <UIHealthController> (); //Initialize icon characterHeadSprite = transform.GetChild(0).GetChild(0).Find("Head").GetComponent <SpriteRenderer> ().sprite; //Start the coroutine that manages the active state of the health bar item. StartCoroutine(ControlHealthBarState()); }
protected override void InitializeNPC() { npcName = "Soldier"; //Sets the initial dialogue for the player. string[] dialogue = new string[] { "INTRUDER!", "Follow us. We will take you to leader." }; GetComponent <NPCPanelController> ().SetCharacterDialogue(dialogue); player = CurrentLevelVariableManagement.GetPlayerReference().GetComponent <PlayerAction> (); }
//Done during the InitializePurchasePanels phase (no real dependencies). void InitializePurchasePanelReference() { //Define required components. currentItemIcon = transform.Find("Animation Controller").Find("Item Icon").GetComponent <SpriteRenderer> (); cost = transform.Find("Animation Controller").Find("Value").Find("Cost").GetComponent <TextMesh> (); //Not accessible in the editor, but can be modified via code. (Looks weird otherwise). cost.GetComponent <MeshRenderer> ().sortingLayerName = "PPanelFront"; cost.GetComponent <MeshRenderer> ().sortingOrder = 0; player = CurrentLevelVariableManagement.GetPlayerReference().transform; playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().gameObject.GetComponent <InventoryFunctions> (); StartCoroutine(CheckForPurchase()); }
//Initializing the NPC protected override void InitializeCharacter() { //Get required components. playerTransform = CurrentLevelVariableManagement.GetPlayerReference().transform; playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> (); //Initialize the NPC before starting to walk around. InitializeNPC(); //Create and start the coroutine. walkAroundCoroutine = WalkAround(); StartCoroutine(walkAroundCoroutine); }
/******************************* MOUSE CLICK MANAGER *******************************/ public void OnPointerClick(PointerEventData data) { if (data.button == PointerEventData.InputButton.Left) { if (currentlyAssigned != null) { if (CurrentLevelVariableManagement.GetPlayerReference().GetComponent <PlayerHealthPanelManager> ().GiveMoneyToPlayer(-currentlyAssigned.price)) { //Add the deassigned item to the player inventory and deduct the price of the item. CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> ().AssignNewItemToBestSlot(new ResourceReferenceWithStack(currentlyAssigned.mainContentReference.uiSlotContent, 1)); ModifyCurrentItemStack(-1); } } } }
//Called whenever the specified action (by the dictionary) occurs. public override void InfluenceEnvironment(MovementAndMethod.PossibleMovements actionKey) { if (physicalFireObject != null) { //Create the object. Vector3 physicalFireOffset = new Vector3(1, 0, 0) * CurrentLevelVariableManagement.GetPlayerReference().GetComponent <PlayerAction> ().GetFacingDirection(); GameObject createdFireObject = (GameObject)(Instantiate(physicalFireObject, CurrentLevelVariableManagement.GetPlayerReference().transform.position + physicalFireOffset + physicalFireObject.transform.localPosition, Quaternion.identity)); createdFireObject.GetComponent <PhysicalFireScript> ().OnFireCreated(); //Used to remove the current item from the hotbar. ChangeStackOfCurrentHotbarItem(1); } else { Debug.LogError("Physical Fire Object does not exist!"); } }
/**************************** TUTORIAL ****************************/ public void OnCurrentLevelCompleted() { Debug.Log("Gathering player data..."); //Get player money. GetComponent <GameData> ().currentPlayerMoney = CurrentLevelVariableManagement.GetPlayerReference().GetComponent <PlayerHealthPanelManager> ().GetPlayerMoney(); Debug.Log("Set player money to " + GetComponent <GameData> ().currentPlayerMoney); //Get player items. GetComponent <GameData> ().currentPlayerItems = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> ().GetAllPlayerItems(); Debug.Log("Player has " + GetComponent <GameData> ().currentPlayerItems.Length + " items"); Debug.Log("Tutorial has been completed!"); //Increment the current level. GetComponent <GameData> ().currentLevel += 1; //Load the Profession Chooser for the next level SceneManager.LoadScene("Profession Chooser"); }
public void InitializeProjectileWithThresholdAndDeviation(Vector3 positionToFireToward, float velocity, float currentHeading, float headingThreshold, float maxRandomDeviation, float ctorArrowPower) { playerObject = CurrentLevelVariableManagement.GetPlayerReference(); //Set physics of the projectile. rb2d = GetComponent <Rigidbody2D> (); //Returned in radians. float radianAngleToTarget = Mathf.Atan2((positionToFireToward.y - transform.position.y), (positionToFireToward.x - transform.position.x)); float degreeAngleToTarget = ScriptingUtilities.RadiansToDegrees(radianAngleToTarget); //Used to set the threshold angles that the arrow can be shot at. if (currentHeading == 0) { if (180 >= degreeAngleToTarget && degreeAngleToTarget >= headingThreshold) { degreeAngleToTarget = headingThreshold; } else if (-180 <= degreeAngleToTarget && degreeAngleToTarget <= -headingThreshold) { degreeAngleToTarget = -headingThreshold; } } else if (currentHeading == 180) { if (0 <= degreeAngleToTarget && degreeAngleToTarget <= 180 - headingThreshold) { degreeAngleToTarget = 180 - headingThreshold; } else if (0 >= degreeAngleToTarget && degreeAngleToTarget >= -180 + headingThreshold) { degreeAngleToTarget = -180 + headingThreshold; } } degreeAngleToTarget += Random.Range(0, maxRandomDeviation) - maxRandomDeviation / 2; transform.localRotation = Quaternion.Euler(new Vector3(0, 0, degreeAngleToTarget)); rb2d.velocity = new Vector2(velocity * Mathf.Cos(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget)), velocity * Mathf.Sin(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget))); arrowPower = ctorArrowPower; //Start the coroutine that checks when the arrow should be destroyed (takes up memory space) StartCoroutine(DestroyIfDistanceFromPlayer()); }
void InitializeTimeIndicationSystem() { //Get Player player = CurrentLevelVariableManagement.GetPlayerReference().transform; //Get the camera. mainCamera = transform.parent.GetComponent <Camera> (); //Get main directional light. mainLight = GetComponent <Light> (); //Get sun sunTransform = transform.Find("Sun"); sunlight = sunTransform.Find("Sunlight").GetComponent <Light> (); initialSunlightIntensity = sunlight.intensity; //Get moon moonTransform = transform.Find("Moon"); moonlight = moonTransform.Find("Moonlight").GetComponent <Light> (); initialMoonlightIntensity = moonlight.intensity; StartCoroutine("ControlSunAndMoonLighting"); }
//Called by LevelEventManager. void InitializeHotbarManager() { //Define player and hotbar slots. Transform slotParent = transform.Find("Slots"); playerObject = CurrentLevelVariableManagement.GetPlayerReference(); playerCostumeManager = playerObject.transform.Find("FlippingItem").Find("Character").GetComponent <PlayerCostumeManager>(); hotbarSlots = new HotbarSlotScript[slotParent.childCount]; for (int i = 0; i < slotParent.childCount; i++) { hotbarSlots[i] = slotParent.GetChild(i).GetComponent <HotbarSlotScript> (); hotbarSlots[i].masterHotbarManager = this; } previouslyActiveSlot = -1; currentlyActiveSlot = 0; StartCoroutine(CheckForActiveItemKey()); StartCoroutine(CheckForPlayerDropItem()); }
public void Initialize() { player = CurrentLevelVariableManagement.GetPlayerReference ().transform; StartCoroutine (MoveTowardsPlayer()); }