// Use this for initialization protected virtual void Start() { AnalyticsEvent.GameStart(new Dictionary <string, object> { { "player", PlayerPrefs.GetString("Settings.Name", "玩家") } }); scaleSensitivity = (float)PlayerPrefs.GetInt("Settings.ScaleSensitivity") / 500; #region Init variable gaming = false; pens = new List <GameObject>(); pens.Add(Instantiate(GameObject.Find("Global").GetComponent <Global>().peninsp.Peek(), new Vector3(Random.Range(-0.7f, 0.7f), 1f, Random.Range(-0.7f, 0.7f)), Random.rotation)); for (int i = 1; i < numPlayer; i++) { pens.Add(Instantiate(GameObject.Find("Global").GetComponent <Global>().pens[Random.Range(0, GameObject.Find("Global").GetComponent <Global>().pens.Count)], new Vector3(Random.Range(-0.7f, 0.7f), 1f, Random.Range(-0.7f, 0.7f)), Random.rotation)); } rounds = new Queue <GameObject>(pens); Physics.gravity = new Vector3(0f, -9.81f, 0f); #endregion #region init controller foreach (GameObject i in pens) { i.name = ExternalFunctionality.GenID(6); if (pens.IndexOf(i) == 0) { i.AddComponent <Player>(); i.tag = "Local"; i.name = PlayerPrefs.GetString("Settings.Name", "玩家"); } else { i.AddComponent <AI>(); } } #endregion Invoke("StartGame", 3f); abilityInfo = GameObject.Find("AbilityInfo"); abilityInfo.SetActive(false); GameObject.Find("Channel").GetComponent <Text>().text = "游戏即将开始"; #region Set Cursor Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; #endregion }
void Start() { acopy = a; bcopy = b; drawer = GetComponent <LineRenderer>(); float verdist = (a.position.x - b.position.x) / verAmount - 1; for (int i = 0; i < verAmount; i++) { verLines.Add(new GameObject()); } foreach (GameObject i in verLines) { i.AddComponent <LineRenderer>(); i.GetComponent <LineRenderer>().positionCount = 2; i.GetComponent <LineRenderer>().SetWidth(width, width); i.GetComponent <LineRenderer>().material = Resources.Load <Material>("Models/Texture"); i.name = "verLine_" + verLines.IndexOf(i); //Instantiate(i); } for (int i = 0; i < horAmount; i++) { horLines.Add(new GameObject()); } foreach (GameObject i in horLines) { i.AddComponent <LineRenderer>(); i.GetComponent <LineRenderer>().positionCount = 2; i.GetComponent <LineRenderer>().SetWidth(width, width); i.GetComponent <LineRenderer>().material = Resources.Load <Material>("Models/Texture"); i.name = "horLine_" + horLines.IndexOf(i); //Instantiate(i); } for (int i = 0; i < obj.Length; i++) { if (i == 0) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/ДомВторовых"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Mat"); objects.Add(cube); } if (i == 1) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/arka"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Arka_Mat"); cube.transform.Rotate(new Vector3(0, -90, 0)); objects.Add(cube); } if (i == 2) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/ДомТвор"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Творч"); cube.transform.Rotate(new Vector3(-90, 0, 0)); objects.Add(cube); } if (i == 3) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Костел"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Собор"); objects.Add(cube); } if (i == 4) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Синагога"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Mat"); objects.Add(cube); } if (i == 5) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Худож.Музей"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/ХудожМузей"); cube.transform.Rotate(new Vector3(-90, -90, 0)); objects.Add(cube); } if (i == 6) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Часовня"); cube.transform.Rotate(new Vector3(-90, 0, 0)); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Часовня"); objects.Add(cube); } if (i == 7) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Вокзал"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Vokzal_mat"); objects.Add(cube); } if (i == 8) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Танк"); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Mat"); objects.Add(cube); } if (i == 9) { GameObject cube = new GameObject(); cube.AddComponent <MeshFilter>(); cube.GetComponent <MeshFilter>().mesh = Resources.Load <Mesh>("Models/Пожарная ст."); cube.AddComponent <MeshRenderer>(); cube.GetComponent <Renderer>().material = Resources.Load <Material>("Models/Пожарная"); cube.transform.Rotate(new Vector3(-90, 0, 0)); objects.Add(cube); } } foreach (GameObject i in objects) { i.AddComponent <MeshRenderer>(); } }
// Start is called before the first frame update void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } for (int ring = 1; ring <= numberOfRings; ring++) { GameObject currentRing = new GameObject(); float circumference = (float)(Mathf.PI * 2 * radius * ring); int numberOfBlocks = Mathf.CeilToInt(circumference / lengthOfBlock); float currentRadius = (float)(radius * ring); List <GameObject> blocksOnCurrentRing = new List <GameObject>(); Bounds? lastBounds = null; for (int block = 1; block <= numberOfBlocks; block++) { if (Random.Range(0, 100) <= randomCapProb * 100) { continue; } float currentAngle = (360f / numberOfBlocks) * block; Vector3 position = PointOnCircle(currentRadius + Random.Range(-offsetRadius, offsetRadius), currentAngle + Random.Range(-offsetRotation, offsetRotation)); //Debug.Log("currentAngle: " + currentAngle + " numberOfBlocks: " + numberOfBlocks + " block: " + block + " xPos: " + position.x + " yPos: " + position.y); GameObject currentBlock = Instantiate(wallPrefab, position, Quaternion.Euler(0, 360 - currentAngle + Random.Range(-offsetAngle, offsetAngle), 0)); currentBlock.transform.SetParent(currentRing.transform); blocksOnCurrentRing.Add(currentBlock); } currentRing.AddComponent <NavMeshSurface>(); currentRing.layer = 19; currentRing.GetComponent <NavMeshSurface>().collectObjects = CollectObjects.Children; currentRing.GetComponent <NavMeshSurface>().BuildNavMesh(); foreach (GameObject block in blocksOnCurrentRing) { Bounds currentBlockBounds = block.GetComponent <BoxCollider>().bounds; currentBlockBounds.Expand(-1.5f); if (lastBounds != null) { Bounds old = lastBounds ?? new Bounds(); if (!currentBlockBounds.Intersects(old)) { Vector3 closestPointOld = old.ClosestPoint(block.transform.position); closestPointOld.y += old.extents.y; Vector3 closestPointNew = currentBlockBounds.ClosestPoint(closestPointOld); closestPointNew.y += currentBlockBounds.extents.y; if (maxLinkDistance >= Vector3.Distance(closestPointOld, closestPointNew)) { NavMeshHit hit; NavMeshLink newLink = block.AddComponent <NavMeshLink>(); NavMesh.SamplePosition(closestPointNew, out hit, maxLinkDistance, NavMesh.AllAreas); newLink.startPoint = block.transform.InverseTransformPoint(hit.position); NavMesh.SamplePosition(closestPointOld, out hit, maxLinkDistance, NavMesh.AllAreas); newLink.endPoint = block.transform.InverseTransformPoint(hit.position); newLink.bidirectional = true; newLink.autoUpdate = true; } } } lastBounds = currentBlockBounds; } Rings.Add(currentRing); } }
void OnMouseUpAsButton() { if ((currentRowNumber + 1) <= 12) //checking if there's any empty space on the platform to place new balls { //checking if all four balls have been placed in the row for (int i = 1; i <= CodeCreator.codeLength; i++) { if (colorTable[currentRowNumber, i] == null) { return; } } currentRowNumber++; justChangedRow = true; //adding colliders to row with currentRowNumber string rowTag2 = "Row " + (currentRowNumber).ToString(); GameObject[] tagList2 = GameObject.FindGameObjectsWithTag(rowTag2); foreach (GameObject i in tagList2) { i.AddComponent <CircleCollider2D>(); if (i.name.StartsWith("Hemisphere")) { i.GetComponent <CircleCollider2D>().radius = 0.06f; } } //removing colliders from row with previous currentRowNumber string rowTag = "Row " + (currentRowNumber - 1).ToString(); GameObject[] tagList; tagList = GameObject.FindGameObjectsWithTag(rowTag); foreach (GameObject i in tagList) { Destroy(i.GetComponent <CircleCollider2D>()); } justChangedRow = false; } //SCORING ANSWERS int redPoints = 0, whitePoints = 0; //Creating a clone of Code table string[] Code; Code = new string[5]; for (int i = 1; i <= 4; i++) { Code[i] = CodeCreator.Code[i]; } //Scoring red points for (int codeBall = 1; codeBall <= 4; codeBall++) { for (int ball = 1; ball <= 4; ball++) { if (colorTable[currentRowNumber - 1, ball] == Code[codeBall] && ball == codeBall) { redPoints++; colorTable[currentRowNumber - 1, ball] = null; Code[codeBall] = null; } } } //Scoring white points for (int codeBall = 1; codeBall <= 4; codeBall++) { for (int ball = 1; ball <= 4; ball++) { if (colorTable[currentRowNumber - 1, ball] != null && Code[codeBall] != null) { if (colorTable[currentRowNumber - 1, ball] == Code[codeBall]) { whitePoints++; colorTable[currentRowNumber - 1, ball] = null; Code[codeBall] = null; } } } } if (redPoints > 0) { Animate(true, redPoints); } if (whitePoints > 0) { Animate(false, whitePoints); } newButton = Instantiate(Resources.Load("Prefabs/GreenRoundButton", typeof(GameObject))) as GameObject; //making the white lamp glow in green newButton.transform.position = gameObject.transform.position; Destroy(gameObject); }