void Update() { if (callOnce == false) { bangGetPoint = true; callOnce = true; } if (bangGetPoint) { Vector3 randomPoint = GetRandomPointOnMesh(lookupCollider.sharedMesh) * 0.3f; randomPoint += lookupCollider.transform.position; //UGLIEST CODE ALIVE -- PROTECT YOUR EYES sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = new Vector3(randomPoint.x, 1f, randomPoint.z); //sphere.GetComponent<Renderer>().material.color = new Color(0, 1, 0, 1); sphere.tag = "PickUp"; WallRotate wrScript = sphere.AddComponent <WallRotate>(); wrScript.ySpeed = -10.0f; sphere.GetComponent <Collider>().isTrigger = true; if (roomManager.points == roomManager.maxPoints - roomManager.spherePoints) { Material newMat = Resources.Load("Collectable", typeof(Material)) as Material; sphere.GetComponent <Renderer>().material = newMat; Color color = new Color(0, 0, 1, 1); sphere.GetComponent <Renderer>().material.SetColor("_EmissionColor", color); } else { Material newMat = Resources.Load("Collectable", typeof(Material)) as Material; sphere.GetComponent <Renderer>().material = newMat; } bangGetPoint = false; } }
public void GenerateLevelData(bool withBackup = false) { Debug.Log(withBackup); if (withBackup) { level = backupLevel; } else { // Push all data to level // Gain bomb data List <BombInfo> bombInfos = new List <BombInfo>(); List <WallInfo> wallInfos = new List <WallInfo>(); level = new Level(levelIndex, numberOfClick, tutorialContent, bombInfos, wallInfos, extraBombs, normalLevel, shooterLevel, waveLevel, targetLevel, acidLevel); LevelUtil.setCurrentLevel(level); GameObject[] bombs = findGameObjectsWithTag("bomb"); for (int i = 0; i < bombs.Length; i++) { GameObject bomb = bombs[i]; BombInfo bombInfo = new BombInfo(); Explode bombExplode = bomb.GetComponent <Explode>(); bombInfo.initAngle = -1 * bombExplode.initAngle; bombInfo.type = bombExplode.type; bombInfo.isLocked = bombExplode.isLocked; bombInfo.timeout = bombExplode.timeout; BombRotate bombRotate = bomb.GetComponent <BombRotate>(); if (bombRotate.speed > 0) { bombInfo.rotate = new BombRotateData(bombRotate.isClockwise, bombRotate.speed); } else { bombInfo.rotate = null; } BombMovement bombMovement = bomb.GetComponent <BombMovement>(); if (bombMovement.speed > 0) { bombInfo.initPosition.Fill(bomb.GetComponent <Explode>().initPosition); MyVector3[] points = new MyVector3[bombMovement.points.Count]; for (int j = 0; j < bombMovement.points.Count; j++) { points[j] = new MyVector3(); points[j].Fill(bombMovement.points[j]); } bombInfo.movement = new BombMovementData(bombMovement.type, points, bombMovement.distances, bombMovement.speed, bombMovement.radius, bombMovement.isClockwise, bombMovement.initAngle); } else { bombInfo.initPosition.Fill(bomb.transform.position); bombInfo.movement = null; } bombInfos.Add(bombInfo); } // Gain wall data GameObject[] walls = findGameObjectsWithTag("wall"); for (int i = 0; i < walls.Length; i++) { GameObject wall = walls[i]; WallInfo wallInfo = new WallInfo(); wallInfo.initAngle = wall.GetComponent <Wall>().initAngle; wallInfo.initPosition.Fill(wall.transform.position); wallInfo.maxHealth = wall.GetComponent <Wall>().maxHealth; wallInfo.currentHealth = wall.GetComponent <Wall>().currentHealth; wallInfo.type = wall.GetComponent <Wall>().type; WallRotate wallRotate = wall.GetComponent <WallRotate>(); if (wallRotate.speed > 0) { wallInfo.rotate = new WallRotateData(wallRotate.isClockwise, wallRotate.speed); } else { wallInfo.rotate = null; } WallMovement wallMovement = wall.GetComponent <WallMovement>(); if (wallMovement.speed > 0) { wallInfo.initPosition.Fill(wall.GetComponent <Explode>().initPosition); MyVector3[] points = new MyVector3[wallMovement.points.Count]; for (int j = 0; j < wallMovement.points.Count; j++) { points[j] = new MyVector3(); points[j].Fill(wallMovement.points[j]); } wallInfo.movement = new WallMovementData(wallMovement.type, points, wallMovement.distances, wallMovement.speed, wallMovement.radius, wallMovement.isClockwise, wallMovement.initAngle); } else { wallInfo.initPosition.Fill(wall.transform.position); wallInfo.movement = null; } wallInfos.Add(wallInfo); } level.walls = wallInfos; level.bombs = bombInfos; backupLevel = level; } }