void Start() { if (instance == null) { instance = this; } }
public PowerAction(Actor owner, int powerSNO) : base(owner) { _power = PowerLoader.CreateImplementationForPowerSNO(powerSNO); _power.User = owner; _powerRan = false; _baseAttackRadius = this.Owner.ActorData.Cylinder.Ax2 + _power.EvalTag(PowerKeys.AttackRadius) + 1.5f; _ownerMover = new ActorMover(owner); }
void Awake() { health = GetComponent <Health>(); audioSource = GetComponent <AudioSource>(); collider2d = GetComponent <Collider2D>(); //spriteRenderer = GetComponent<SpriteRenderer>(); //animator = GetComponent<Animator>(); remainingJumps = allowedJumps; powerScript = powerDisplay.GetComponent <PowerScript>(); }
void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.name == "Car") { Debug.Log("You won!"); powerScript = powerDisplay.GetComponent<PowerScript>(); powerScript.activateVictory(); } }
public void invokeJump() { // player is no longer charging isCharging = false; // get the game object tagged as "Power" GameObject powerObject = GameObject.FindWithTag("Power"); // inside the object tagged as "Power", get PowerScript script PowerScript script = powerObject.GetComponent("PowerScript") as PowerScript; // destoy the power bar Destroy(GameObject.FindWithTag("Power")); // find the object tagged as "Player" and send "Jump" message, with the proper force GameObject.FindWithTag("Player").SendMessage("Jump", maxJumpForce * script.chargePower + 50); buttonDown = false; }
// Start is called before the first frame update void Start() { remainingJumps = allowedJumps; powerScript = powerDisplay.GetComponent <PowerScript>(); }
public void loggerMethod(int currentSuccess, float poleDistance, float poleHeight, string currentPoleName, string currentPoleMag, string currentPoleFric, int getScore, string currentPoleMagAr, string nearestPoleName, float distanceOfNearestPoleXPosition, float assistanceLevel, float hindranceLevel) { GameObject powerObject = GameObject.FindWithTag("Power"); // get the game object tagged as "Power" PowerScript powerScript = powerObject.GetComponent("PowerScript") as PowerScript; // inside the object tagged as "Power", get PowerScript script // We actually do not need this section -- but it's still here ! What a waste of energy and time // Since everything from scripts are getting here without a proper serialization as we are updating the project quite a few times // this section makes everything in a serial order for the log file string PoleNumber = currentPoleName; // the current pole number where the player is string PoleDistance = poleDistance.ToString(); // the current pole X position string PoleHeight = poleHeight.ToString(); // the current pole Y position string PoleMagnetism = currentPoleMag; // the current pole's magnetism string PoleFriction = currentPoleFric; // the current pole's materials friction string Power = powerScript.mouseDepressPower.ToString(); // the power that is set to the string PoleMagnetismArea = currentPoleMagAr; // Magnetism Area of the pole string DistanceToTheNearestPole = distanceOfNearestPoleXPosition.ToString(); string trajectoryAssistance = assistanceLevel.ToString(); string trajectoryHindrance = hindranceLevel.ToString(); int currentScore = getScore; // the current score of the player int Success = currentSuccess; // success ? int Failure = 0; if (currentSuccess == 0) { Failure = 1; // if not success then failed } // Check for duplicate log // It looks like due to duplicate hit there might be more than one log for a single pole // Hacked! if (prePoleNumber == PoleNumber && prePower == Power && preDistanceToTheNearestPole == DistanceToTheNearestPole) { LogData = false; } else { LogData = true; } // Identifying Round Sections // This section must be deleted after the peak-end study // First check if the nearest Pole Number has a length more than 4 int poleNumberID = 0; if (nearestPoleName.Length > 4 && !nearestPoleName.Equals("poleEnd")) { poleNumberID = int.Parse(nearestPoleName.Substring(4)); } // Get the string of the filename string nameOfFile = MainScript.refFileName.ToString(); if ((poleNumberID >= 1 && poleNumberID <= 8) || (poleNumberID >= 13 && poleNumberID <= 20)) { poleSection = "Neutral"; } else if (((poleNumberID >= 9 && poleNumberID <= 12) || (poleNumberID >= 21 && poleNumberID <= 24)) && MainScript.refFileName.Substring(nameOfFile.Length - 8).Equals("Positive")) { poleSection = "Positive"; } else if (((poleNumberID >= 9 && poleNumberID <= 12) || (poleNumberID >= 21 && poleNumberID <= 24)) && MainScript.refFileName.Substring(nameOfFile.Length - 8).Equals("Negative")) { poleSection = "Negative"; } else { poleSection = ""; } // Reset ElapsedTime timer after specific PoleSection if (PoleNumber.Equals("Pole08") && isFirstOccurence) { eTNeutral = MainScript.elapsedTime; MainScript.elapsedTime = 0; isFirstOccurence = false; } else if (PoleNumber.Equals("Pole09") || PoleNumber.Equals("Pole010") || PoleNumber.Equals("Pole011")) { isFirstOccurence = true; } else if (PoleNumber.Equals("Pole012") && isFirstOccurence) { eTOther = MainScript.elapsedTime; MainScript.elapsedTime = 0; isFirstOccurence = false; } else if (PoleNumber.Equals("Pole013") || PoleNumber.Equals("Pole014") || PoleNumber.Equals("Pole015")) { isFirstOccurence = true; } else if (PoleNumber.Equals("Pole020") && isFirstOccurence) { eTNeutral += MainScript.elapsedTime; MainScript.elapsedTime = 0; isFirstOccurence = false; } else if (PoleNumber.Equals("Pole021") || PoleNumber.Equals("Pole022") || PoleNumber.Equals("Pole023")) { isFirstOccurence = true; } else if (PoleNumber.Equals("PoleEnd") && isFirstOccurence) { eTOther += MainScript.elapsedTime; MainScript.elapsedTime = 0; } prePoleNumber = PoleNumber; // set pre for this data prePower = Power; // set Power equal to prePower preDistanceToTheNearestPole = DistanceToTheNearestPole; // set DistanceToTheNearestPole equal to the preDistanceToTheNearestPole if (LogData) { string url = MainScript.server_url + "/loggame"; WWWForm form = new WWWForm(); form.AddField("poleNumber", PoleNumber); form.AddField("poleDistance", PoleDistance); form.AddField("poleHeight", PoleHeight); form.AddField("currentTime", MainScript.timer.ToString()); form.AddField("elapsedTimeNeutral", eTNeutral.ToString()); form.AddField("elapsedTimePeakEnd", eTOther.ToString()); form.AddField("nearestPoleName", nearestPoleName); form.AddField("poleSection", poleSection); form.AddField("distanceToTheNearestPole", DistanceToTheNearestPole); form.AddField("magnetismLevel", PoleMagnetism); form.AddField("magnetismArea", PoleMagnetismArea); form.AddField("trajectoryAssistance", trajectoryAssistance); form.AddField("trajectoryHindrance", trajectoryHindrance); form.AddField("friction", PoleFriction); form.AddField("power", Power); form.AddField("score", currentScore); form.AddField("success", Success); form.AddField("failure", Failure); form.AddField("successWithoutAnyAssist", successWithoutAnyTypeOfAssist); // Has the game has been initialised or not. Restarting after death will be set to 0 form.AddField("gameInitialised", StartScreenScript.gameInitialised); //Log data in the unity inspector // Un-Comment the next section for showing it into the unity inspector //Debug.Log("PoleNumber: " + PoleNumber + "\n" + //"Pole Distance: " + PoleDistance + "\n" + //"PoleHeight: " + PoleHeight + "\n" + //"Current Time in Sec: " + MainScript.timer.ToString() + "\n" + //"Elapsed Time Neutral: " + eTNeutral.ToString() + "\n" + //"Elapsed Time Peak End: " + eTOther.ToString() + "\n" + //"Nearest Pole Number: " + nearestPoleName + "\n" + //"Pole Section: " + poleSection + "\n" + //"DistanceToTheNearestPole: " + DistanceToTheNearestPole + "\n" + //"PoleMagnetism: " + PoleMagnetism + "\n" + //"Magnetism Area: " + currentPoleMagAr + "\n" + //"Trajectory Assistance: " + trajectoryAssistance + "\n" + //"Trajectory Hindrance: " + trajectoryHindrance + "\n" + //"Pole Friction: " + PoleFriction + "\n" + //"Power: " + Power + "\n" + //"Current Score: " + currentScore + "\n" + //"Success: " + Success + "\n" + //"Failure: " + Failure + "\n" + //"Player Score Without Magnetism: " + playerScoreWithoutMagnetism + "\n" + //"Game Initialised: " + StartScreenScript.gameInitialised); WWW www = new WWW(url, form); StartCoroutine(WaitForRequest(www)); } }
// This function is executed at each of our game frame void Update() { //if(Cursor.lockState != CursorLockMode.Confined) //Cursor.lockState = CursorLockMode.Confined; // keep confined in the game window //// Depreciated for UNITY 5_3 // Check the Day/Night Settings GameObject SunLight = GameObject.Find("Sun"); SunLight.GetComponent <Light>().intensity = currentLightSettings; // Turning on the moon when the light intensity goes down GameObject Moon = GameObject.Find("MoonCrescent"); GameObject SunHalo = GameObject.Find("SunHalo"); GameObject Pl1 = GameObject.Find("Point light_1"); GameObject Pl2 = GameObject.Find("Point light_2"); GameObject Pl3 = GameObject.Find("Point light_3"); if (currentLightSettings < 0.25) { SunHalo.GetComponent <SpriteRenderer>().enabled = false; // Turn off Sun SunHalo.GetComponent <SpriteRenderer>().enabled = false; Moon.GetComponent <SpriteRenderer>().enabled = true; // Turn on Moon Pl1.GetComponent <Light>().enabled = true; Pl2.GetComponent <Light>().enabled = true; Pl3.GetComponent <Light>().enabled = true; } else { SunHalo.GetComponent <SpriteRenderer>().enabled = true; // Turn on Sun Moon.GetComponent <SpriteRenderer>().enabled = false; // Turn off Moon Pl1.GetComponent <Light>().enabled = false; Pl2.GetComponent <Light>().enabled = false; Pl3.GetComponent <Light>().enabled = false; } // Find the player object playerObject = GameObject.FindGameObjectWithTag("Player"); realTrailObject = GameObject.FindGameObjectWithTag("RealTrail"); //Add a shortcut button for turning on the trajectory TrajectoryPredictor trajectoryScript01 = playerObject.GetComponent("TrajectoryPredictor") as TrajectoryPredictor; TrajectoryPredictor trajectoryScript02 = realTrailObject.GetComponent("TrajectoryPredictor") as TrajectoryPredictor; if (PlayerPrefs.GetString("DebuggerMode").Equals("True")) { //// For Player trajectoryScript01.drawDebugOnUpdate = true; trajectoryScript01.drawDebugOnPrediction = true; //// For Real Trail trajectoryScript02.drawDebugOnUpdate = true; trajectoryScript02.drawDebugOnPrediction = true; } else { bool ctrl = Input.GetKey(KeyCode.RightControl); bool alt = Input.GetKey(KeyCode.RightAlt); bool t = Input.GetKeyDown(KeyCode.T); if ((ctrl && alt && t) || (alt && ctrl && t)) { if (!pressedOnce) { pressedOnce = true; } else { pressedOnce = false; } } if (pressedOnce) { // For Player trajectoryScript01.drawDebugOnUpdate = true; trajectoryScript01.drawDebugOnPrediction = true; // For Real Trail trajectoryScript02.drawDebugOnUpdate = true; trajectoryScript02.drawDebugOnPrediction = true; } else if (!pressedOnce) { // For Player trajectoryScript01.drawDebugOnUpdate = false; trajectoryScript01.drawDebugOnPrediction = false; // For Real Trail trajectoryScript02.drawDebugOnUpdate = false; trajectoryScript02.drawDebugOnPrediction = false; } } // Check the Magnetism Properties and trail renderer properties NinjaScript ninjaScript = playerObject.GetComponent("NinjaScript") as NinjaScript; if (magnetismOn) { ninjaScript.magnetismOn = true; } else { ninjaScript.magnetismOn = false; } // Check the Trajectory Assistance Properties and trail renderer properties if (trajectoryAssistanceOn) { ninjaScript.trajectoryAssistanceOn = true; } else { ninjaScript.trajectoryAssistanceOn = false; } // Timer Game Object GameObject timerObject = GameObject.Find("Timer"); // Timer settings shown on top of the screen if (timeStarted == true && timePaused == false && timer > 1) { timer -= Time.deltaTime; elapsedTime += Time.deltaTime; //elapsedTime = totalGameTime * 60 - timer; int minutes = Mathf.FloorToInt(timer / 60F); int seconds = Mathf.FloorToInt(timer - minutes * 60); string niceTime = string.Format("{0:00}:{1:00}", minutes, seconds); timerObject.GetComponent <Text>().text = niceTime; } else if (timer <= 1 && timeStarted == true && timePaused == false && !calledOnce) { timeStarted = false; timePaused = true; // Show the Game Over Screen again but with Time Out wriiten // Enable Canvas section GameObject canvasObject = GameObject.Find("Canvas"); Instantiate(canvasObject); canvasObject.GetComponent <Canvas>().enabled = true; Image panelImage = canvasObject.GetComponentInChildren <CanvasRenderer>().GetComponent <Image>(); panelImage.color = new Color(0, 0, 0, 1); //newPanelColor; // Disable Game Over Image GameObject gameOverObj = GameObject.Find("GameOverImage"); gameOverObj.GetComponent <Image>().enabled = false; // Enable TimeOut Image Text TimeOutObj = GameObject.Find("TimeOutText").GetComponent <Text>(); TimeOutObj.enabled = true; // Disbale the restart button GameObject buttonRestart = GameObject.Find("ButtonRestart"); buttonRestart.GetComponent <Image>().enabled = false; buttonRestart.GetComponent <Button>().enabled = false; // Destroy the player first to remove any additional log GameObject player = GameObject.FindGameObjectWithTag("Player"); Destroy(player); playerIsAlive = false; // pause for 5 seconds and then destroy everything StartCoroutine(TimeUp(5)); } else if (timePaused) { timerObject.GetComponent <Text>().text = "PAUSED"; RectTransform rt = timerObject.GetComponent <RectTransform>(); rt.localPosition = new Vector2(35, 0); rt.localScale = new Vector2(0.60F, 0.60F); } //float playerYPosition = GameObject.FindWithTag("Player").transform.position.y; float playersXvelocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D>().velocity.x; float playersYvelocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody2D>().velocity.y; // Mouse button is down, but ninja isn't jumping/falling (its y velocity is zero) and the ninja is not charging if (Input.GetButtonDown("Fire1") && playersXvelocity == 0 && playersYvelocity == 0 && !isCharging && playerIsAlive && !timePaused) { // check if the real trail exist or not if (GameObject.FindWithTag("RealTrail") != null) { //Destroy(GameObject.FindWithTag("RealTrail")); GameObject.FindWithTag("RealTrail").transform.position = playerObject.transform.position; GameObject.FindWithTag("RealTrail").transform.rotation = playerObject.transform.rotation; //Debug.Log("realTrailObject.transform.position: " + realTrailObject.transform.position); } isCharging = true; // now the ninja will be charging } // Mouse button released and the ninja is charging but not jumping/falling (its y velocity is zero) if (Input.GetButtonUp("Fire1") && playersXvelocity == 0 && playersYvelocity == 0 && isCharging && playerIsAlive && !timePaused) { isCharging = false; // player is no longer charging so set the isCharging to false GameObject powerObject = GameObject.FindWithTag("Power"); // get the game object tagged as "Power" PowerScript script = powerObject.GetComponent("PowerScript") as PowerScript; // inside the object tagged as "Power", get PowerScript script GameObject player = GameObject.FindGameObjectWithTag("Player"); player.SendMessage("Jump", maxJumpForce * script.chargePowerSender); // find the object tagged as "Player" and send "Jump" message, with the proper force updateScore = true; // Set the updateScore to true because the player just jumped } }
void Awake() { P.init(); //init the magic number for screen scaling Time.timeScale = 1f; //just in case it had been changed WorldSelectBanner.Reset(); SquareClick.Reset(); //create the boundary at the screen's size GameObject boundary = new GameObject(); boundary.name = "Boundary"; boundary.tag = "Boundary"; BoxCollider2D boundaryColl = boundary.AddComponent <BoxCollider2D> (); boundaryColl.isTrigger = true; boundaryColl.size = new Vector2(P.pocP(2f, Side.W), P.pocP(2f, Side.H)); //background GameObject bg = new GameObject("Background"); bg.transform.position = Vector3.zero; bg.transform.localScale = new Vector3(P.pocSGame(1f, Side.W), P.pocSGame(1f, Side.H), 1f); SpriteRenderer srBg = bg.AddComponent <SpriteRenderer> (); srBg.sortingOrder = -100; srBg.sprite = Resources.Load <Sprite> ("pixel"); //Level_mX_XX try{ switch (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.ToCharArray() [7]) { case '1': srBg.color = new Color(0.22352941176470588235294117647059f, 0.32549019607843137254901960784314f, 0.64313725490196078431372549019608f, 1f); break; case '2': srBg.color = new Color(0.64705882352941176470588235294118f, 0.21568627450980392156862745098039f, 0.21568627450980392156862745098039f, 1f); break; case '3': srBg.color = new Color(0.23529411764705882352941176470588f, 0.18039215686274509803921568627451f, 0.11372549019607843137254901960784f, 1f); break; default: srBg.color = new Color(1f, 0f, 0f, 1f); break; } }catch (Exception) { srBg.color = new Color(1f, 0f, 0f, 1f); } //params GameObject para = GameObject.FindGameObjectWithTag("Params"); if (para != null) { ReferenceObj refe = para.GetComponent <ReferenceObj> (); easyMode = (bool)refe.GetReferenceByName("isEasy"); coopMode = (bool)refe.GetReferenceByName("isCoop"); Destroy(para); } //player if (coopMode) { GameObject player1 = Instantiate(playerPrefab) as GameObject; GameObject player2 = Instantiate(playerPrefab) as GameObject; player1.name = "player1"; player2.name = "player2"; // Destroy (player1.GetComponent<PlayerScript> ()); // Destroy (player2.GetComponent<PlayerScript> ()); PlayerCoopScript pScript1 = player1.AddComponent <PlayerCoopScript> (); PlayerCoopScript pScript2 = player2.AddComponent <PlayerCoopScript> (); PlayerCoopScript.LinkPlayers(pScript1, pScript2); player1.transform.position = new Vector2(0, P.pocP(-0.7f, Side.HEIGHT)); player2.transform.position = new Vector2(0, P.pocP(0.7f, Side.HEIGHT)); mat = player1.GetComponent <MeshRenderer> ().material; contourColor = mat.color; playerInstance = pScript1; } else { GameObject player = Instantiate(playerPrefab) as GameObject; player.transform.position = new Vector2(0, P.pocP(-0.7f, Side.HEIGHT)); mat = player.GetComponent <MeshRenderer> ().material; playerInstance = player.AddComponent <PlayerScript> (); contourColor = mat.color; } PlayerScript.afterColorChange += OnColorChange; //obstacles GameObject[] obs = GameObject.FindGameObjectsWithTag("Obstacle"); obstacles.AddRange(obs); StartCoroutine(Enabler()); startTime = Time.time; foreach (object g in obstacles) { ((GameObject)g).SetActive(false); if (((GameObject)g).GetComponent <GameObstacle> ().startAtTime < timeOffset) { Destroy((GameObject)g); } } //setup UI Data data = Data.GetInstance(); GameObject ui = Instantiate(Resources.Load <GameObject> ("PowerIcons/PowerButtons")) as GameObject; if (easyMode) { ui.transform.FindChild("LifeCount").gameObject.SetActive(true); } for (int i = 0; i < 4; i++) { GameObject powUi = ui.transform.FindChild("Power" + (i + 1)).gameObject; PowerScript powScript = powUi.GetComponent <PowerScript> (); Slider slider = powUi.GetComponent <Slider> (); PowerAttribut attrib = data.GetPowerAttribut(data.selectedPowers [i]); Power pow = Power.GetInstance(data.selectedPowers [i], slider); if (data.selectedPowers [i] == Powers.Null) { powUi.SetActive(false); } else { pow.SetAttribut(attrib); powScript.power = pow; powUi.transform.FindChild("Icon").GetComponent <Image> ().sprite = pow.icon; } } }