// Initializes the game to the given gameState private void StartGame(int gameState) { if (gameState != 0) { GameObject startStar = Instantiate(star); this.questionStar = startStar; StarScript sScript = (StarScript)startStar.GetComponent("StarScript"); sScript.initiate(initialStarPos.y, initialStarPos, questionStar); this.SelectStar(startStar); startStar.GetComponent <Renderer>().material = defaultMaterialStar; if (gameState == 1) { } else if (gameState == 2) { } else if (gameState == 3) { } else if (gameState == 4) { } //star.transform.position = initialStarPos; } }
public void TeleportTo(int portalId) { if (ListCorrectStars [Stage][ActivatedStars] == portalId) { CurrentStar.isStar = false; Star = ListStars [portalId]; CurrentStar = ListStars [portalId].GetComponent <StarScript> (); LightCurrentStar = ListStars [portalId].GetComponent <LineRenderer> (); CurrentStar.isStar = true; CurrentStar.isActive = true; ActivatedStars++; print("CorrectStars : " + ListCorrectStars [Stage].Count + " Activated Stars : " + ActivatedStars); } if (ListCorrectStars [Stage].Count == ActivatedStars) { PlayerPrefs.SetInt("StageCleared", Stage); print(Application.loadedLevel); if (Stage == 3) { Application.LoadLevel(6); } else { Application.LoadLevel(1); } } }
//Spawns 'newstars' amount of star objects at random x z positions with y = 0, and then rises them up to a random y position //random positions in range of declared bounds public void SpawnStars() { //creates new stars at random positions with 1st being a solution, and others not for (int i = 0; i < newstars; i++) { GameObject newstar = Instantiate(star); StarScript sScript = (StarScript)newstar.GetComponent("StarScript"); if (i == 0) { // keep track of the solution star solutionStar = newstar; // initialize star to be a solution sScript.isSolution = true; string val = (num1 * num2).ToString(); sScript.ChangeTextTo(val); } else { // keep track of non solutions nonSolutionStars.Add(newstar); // initialize star to be a non conflicting wrong answer sScript.isSolution = false; string val = this.CreateFalseSolution(i); sScript.ChangeTextTo(val); } setStarPos(sScript); } }
IEnumerator feelAndPlace(StarScript sScript) { bool isOverlapping = true; float xPos = 1f; float yPos = 1f; float zPos = 1f; while (isOverlapping) { xPos = Random.Range(-xBound, xBound); yPos = Random.Range(yLowBound, yUpBound); zPos = Random.Range(-zBound, zBound); Vector3 endPos = new Vector3(xPos, yPos, zPos); GameObject feeler = Instantiate(feelerStar); feeler.transform.position = endPos; yield return(new WaitForSeconds(0.1f)); if (!feeler.GetComponent <FeelerStarScript>().hasCollided) { isOverlapping = false; } testWaitbool = false; Destroy(feeler); } if (!isOverlapping) { Vector3 startPos = new Vector3(xPos, 0f, zPos); sScript.initiate(yPos, startPos, questionStar); sScript.touched = true; } }
// Handles selecting a star public void SelectStar(GameObject selectedObj) { StarScript sScript = (StarScript)selectedObj.GetComponent("StarScript"); // Selected star is the solution if (sScript.isSolution) { // remove false answers foreach (GameObject star in nonSolutionStars) { Destroy(star); } nonSolutionStars = new List <GameObject>(); this.Retire(questionStar); completedStars.Add(selectedObj); // transition answer star to question star selectedObj.tag = "Untagged"; questionStar = selectedObj; sScript.isSolution = false; // increment number of correctly answered questions and check if game won answeredQuestions = answeredQuestions + 1; if (answeredQuestions == questionsPerGame) { this.GameEnd(true); this.Retire(questionStar); } //if game not one, create a new question and spawn new stars else { num1 = (int)Random.Range(multLowBound, multHighBound); num2 = (int)Random.Range(multLowBound, multHighBound); string newVal = num1.ToString() + " x " + num2.ToString(); sScript.ChangeTextTo(newVal); SpawnStars(); } } // selected star was not the correct answer else { // removese the star sScript.Remove(); this.nonSolutionStars.Remove(selectedObj); // increments the number of wrongly guessed stars wrongAnswers = wrongAnswers + 1; // end game if too many incorrect answers if (wrongAnswers == wrongAnswersPerGame) { this.GameEnd(false); } } }
public void Start() { if (self != this) { self = this; } else { Destroy(gameObject); } }
void OnTriggerEnter2D(Collider2D otherCollider) { StarScript star = otherCollider.gameObject.GetComponent <StarScript> (); if (star != null) { if (star.isPlayer == isPlayer) { Destroy(star.gameObject); starNumber++; } } }
public void moveToFinalImage(int amount, List <GameObject> stars) { List <string> imageKeys = this.pointsToCompatibleImage[amount]; string imageToDisplay = imageKeys[Random.Range(0, imageKeys.Count - 1)]; List <Vector3> imagePoints = this.alterImage(.4f, .4f, this.images[imageToDisplay]); for (int i = 0; i < imagePoints.Count; i++) { StarScript sScript = stars[i].GetComponent <StarScript>(); sScript.targetPos = imagePoints[i]; sScript.minimizeFactor = .5f; } }
// Use this for initialization void Start() { Star = ListStars [0]; CurrentStar = Star.GetComponent <StarScript> (); LightCurrentStar = Star.GetComponent <LineRenderer> (); //Stage = PlayerPrefs.GetInt("Stage"); Stage = Application.loadedLevel - 2; PlayerPrefs.SetInt("StageCleared", 1); //CurrentStarsCount = ListStarsCount[Stage]; List <int> dummyCombination = new List <int> (); dummyCombination.Add(0); ListCorrectStars.Add(dummyCombination); List <int> firstStage = new List <int> (); firstStage.Add(0); firstStage.Add(1); firstStage.Add(2); firstStage.Add(3); firstStage.Add(4); ListCorrectStars.Add(firstStage); List <int> secondStage = new List <int> (); secondStage.Add(0); secondStage.Add(1); secondStage.Add(2); secondStage.Add(3); secondStage.Add(5); secondStage.Add(6); secondStage.Add(4); ListCorrectStars.Add(secondStage); List <int> thirdStage = new List <int> (); thirdStage.Add(0); thirdStage.Add(1); thirdStage.Add(2); thirdStage.Add(3); thirdStage.Add(6); thirdStage.Add(7); thirdStage.Add(4); thirdStage.Add(5); ListCorrectStars.Add(thirdStage); }
// Start is called before the first frame update void Start() { LevelStrings(); starsHolder.SetActive(true); starCount = 0; PlayerPrefs.GetInt(highScore); //get the max stars count for this level playerSwipe = FindObjectOfType <WindSwipe>(); theStars = FindObjectOfType <StarScript>(); theCam = FindObjectOfType <CameraController>(); //by default, win and lose screens are set inactive at start winScreen.SetActive(false); loseScreen.SetActive(false); }
void throwStar() { animator.SetBool("Throwing", true); float sx = transform.position.x + 24.5f * Mathf.Sign(transform.localScale.x); float sy = yPos + 36f; GameObject stargen = Instantiate(star, new Vector3(sx, sy, yPos), Quaternion.identity) as GameObject; StarScript ss = stargen.GetComponent <StarScript>(); if (transform.localScale.x > 0) { ss.deltaX = 2f; } else { ss.deltaX = -2f; } }
// Start is called before the first frame update void Start() { LevelStrings(); starsHolder.SetActive(true); starCount = 0; PlayerPrefs.GetInt(highScore); //get the max stars count for this level PlayerPrefs.GetInt("TypeOfCrate"); //get the type of crate selected theAdsController = FindObjectOfType <AdController>(); playerSwipe = FindObjectOfType <WindSwipe>(); theStars = FindObjectOfType <StarScript>(); theCam = FindObjectOfType <CameraController>(); balloonScript = FindObjectOfType <Balloon>(); //by default, win and lose screens are set inactive at start winScreen.SetActive(false); loseScreen.SetActive(false); }
void OnDestroy() { m_Instance = null; StopAllCoroutines(); }
void Awake() { m_Instance = this; }
// selects an object if selectable and handles clicks on that object private void SelectObject() { //Initialize ray for object detection Ray mray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); var ray = Camera.main.transform.forward; RaycastHit hit; // if camera is pointing at an object if (Physics.Raycast(mray, out hit)) { var selection = hit.transform; // if the object is a star object if (selection.CompareTag(starTag)) { var selectionRenderer = selection.GetComponent <Renderer>(); // if the renderer exists, highlight object if (selectionRenderer != null) { selectionRenderer.material = highlightMaterialStar; } // select the star that the play is looking at if (Input.GetMouseButtonDown(0)) { StarScript script = (StarScript)selection.gameObject.GetComponent("StarScript"); if (script != null) { SelectStar(selection.gameObject); } } // remember transform to deselect prevSelectedObjectTransform = selection; } // if the object is a UI start menu button else if (selection.CompareTag(UIStartMenuTag)) { var selectionRenderer = selection.GetComponent <Renderer>(); // if selection renderer exists, highlight object if (selectionRenderer != null) { selectionRenderer.material = highlightMaterialUI; } // starts the game based off of the button selected if (Input.GetMouseButtonDown(0)) { UIStartScript script = (UIStartScript)selection.gameObject.GetComponent("UIStartScript"); if (script != null) { this.gameState = script.gameStateTrigger; script.Select(); this.StartGame(gameState); } } // remember transform to deselect prevSelectedObjectTransform = selection; } } }
// moves star to random location where it does not overlap with an object // may pass through objects to get to position private void setStarPos(StarScript sScript) { StartCoroutine(feelAndPlace(sScript)); }
// Use this for initialization void Start() { this.ActiveGalaxyIndex = 0; this.residences = new List <string>(); this.professions = new List <string>(); this.volontaires = new List <string>(); this.grades = new List <string>(); this.ages = new List <string>(); this.naissances = new List <string>(); stars = new List <StarScript>(); galaxies = new List <GalaxyScript>(); StarScript prefab = (Resources.Load("Star/StarPrefab", typeof(GameObject)) as GameObject).GetComponent <StarScript>(); this.starsObject = new GameObject(); this.starsObject.name = "stars"; this.starsObject.transform.SetParent(this.transform); this.galaxiesObject = new GameObject(); this.galaxiesObject.name = "galaxies"; this.galaxiesObject.transform.SetParent(this.transform); StarScript star; StreamReader dataFile = new StreamReader(Application.streamingAssetsPath + "/Soldats.csv"); string rawLine = dataFile.ReadLine(); string[] dataLine; string residence, grade, profession, naissance, volontaire; int age, num, anaissance; int width = 0; bool firstLine = true; int i = 0; while (rawLine != null) { dataLine = rawLine.Split(';'); if (firstLine) { width = dataLine.Length; firstLine = false; } else if (dataLine.Length == width) { age = 0; num = 0; System.Int32.TryParse(dataLine[0], out num); System.Int32.TryParse(dataLine[11], out age); if (age >= 16 && !this.ages.Contains(age.ToString())) { this.ages.Add(age.ToString()); } residence = dataLine[13].ToLower(); if (residence != "" && !this.residences.Contains(residence)) { this.residences.Add(residence); } grade = dataLine[15].ToLower(); if (grade != "" && !this.grades.Contains(grade)) { this.grades.Add(grade); } volontaire = dataLine[6].ToLower(); if (volontaire != "" && !this.volontaires.Contains(volontaire)) { this.volontaires.Add(volontaire); } profession = dataLine[3].ToLower(); if (profession != "" && !this.professions.Contains(profession)) { this.professions.Add(profession); } naissance = dataLine[1].ToLower(); if (naissance.Split('/').Length != 3 || naissance.Split('/')[2].Length != 4) { naissance = ""; } else if (naissance.Split('/').Length == 3) { anaissance = 0; System.Int32.TryParse(naissance.Split('/')[2], out anaissance); if (anaissance >= 1902 || anaissance < 1860) { naissance = ""; } } else { naissance = ""; } if (naissance != "" && !this.naissances.Contains(naissance.Split('/')[2])) { this.naissances.Add(naissance.Split('/')[2]); } star = Instantiate(prefab); star.transform.SetParent(this.starsObject.transform); star.name = i.ToString(); star.num = num; star.age = age; star.residence = residence; star.grade = grade; star.profession = profession; star.naissance = naissance; star.volontaire = volontaire; star.joinSpeed = this.joinspeed; star.transform.position = new Vector3(this.minx + Random.value * (this.maxx - minx), this.miny + Random.value * (this.maxy - miny), this.minz + Random.value * (this.maxz - minz)); star.gameObject.SetActive(false); this.stars.Add(star); i++; } rawLine = dataFile.ReadLine(); } dataFile.Close(); this.ChangeCriteria(this.criteria); this.numStars = 0; this.starsWaiting = false; this.noStars = false; this.nextcriteria = false; }
void Start() { bg = GetComponentInChildren <SpriteRenderer> (); stars = GameObject.Find("StarField").GetComponent <StarScript> (); sounds = GetComponents <AudioSource> (); }
//called when the player dies public void cleanLoadLevel(RestartFrom respawning, string lvl) { string level = SceneManager.GetActiveScene().name; //clean anything that needs resetting in Xa xa.cleanXa(); xa.carryingStars = 0; Time.timeScale = 1; xa.playerAirSwording = false; ScreenShakeCamera.screenshakeAmount = 0; ScreenShakeCamera.screenshakeDelay = 0; ScreenShakeCamera.screenshakeTimeSet = 0; ScreenSlash.Reset(); //if not respawning, reset some extra the .xa variables if (respawning == RestartFrom.RESTART_FROM_MENU || respawning == RestartFrom.RESTART_FROM_START) { fa.teleportedOnJumpingMassacre = false; xa.realScore = 0; xa.displayScore = 0; xa.checkpointScore = 0; StarScript.cleanStarsRegister(); xa.lastSpawnPoint = Vector3.zero; xa.deathCountThisLevel = 0; xa.checkpointedStarsThisLevel = 0; xa.hasCheckpointed = false; GhostManager.RewindGhosts(); } switch (respawning) { case RestartFrom.RESTART_FROM_MENU: //Application.LoadLevel(lvl); SceneManager.LoadScene(lvl); break; case RestartFrom.RESTART_FROM_CHECKPOINT: if (xa.hasCheckpointed) { Setup.callFadeOutFunc(level, true, level); } else { // Respawn from the beginning of the level. Reset kills and deaths // if (LevelInfo.restartMusicOnLevelRestart(level)) //{ // xa.bard.audio.time = 0; // if (level == "Boss_run1") xa.bard.audio.time = 106; // } xa.deathCountThisLevel = 0; fa.ResetSpeedrun(); //reset speed run time because you haven't checkpointed Setup.callFadeOutFunc(level, true, level); } break; case RestartFrom.RESTART_FROM_START: //Load the current level from the start //if (LevelInfo.restartMusicOnLevelRestart(level)) //{ // xa.bard.audio.time = 0; // if (level == "Boss_run1") xa.bard.audio.time = 106; //} fa.ResetSpeedrun(); Setup.callFadeOutFunc(level, true, level); break; } // Setup.GC_DebugLog("Deaths: " + xa.deathCountThisLevel); }
private void Retire(GameObject star) { StarScript sScript = (StarScript)star.GetComponent("StarScript"); sScript.Finish(); }