Skip to content
Snippets Groups Projects
Commit fdb88788 authored by Erno Lokkila's avatar Erno Lokkila
Browse files

Game win now possible

parent 2da49f98
No related branches found
No related tags found
No related merge requests found
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4334850820553036048
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2388334960364419616}
m_Layer: 0
m_Name: GameWin
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2388334960364419616
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4334850820553036048}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.5898275, y: 3.887589, z: 0.94433594}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
fileFormatVersion: 2
guid: 80a61f8911aa37046a2d5e13d579c221
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: cf62eacc43e8a40469118b61f12a5364
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveRandomly : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
StartCoroutine("moveAround");
}
private IEnumerator moveAround() {
while (true)
{
float moveTime = Random.value * 2;
float timeSpent = 0;
Vector3 direction = new Vector3(Random.value*2-1,Random.value*2-1, 0);
while (timeSpent < moveTime)
{
transform.position = transform.position + direction*0.01f;
yield return null;
timeSpent += Time.deltaTime;
}
}
}
}
fileFormatVersion: 2
guid: d3063605b31636c4e9998676be17db5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WinGame : MonoBehaviour
{
[SerializeField]
private GameObject housePrefab = null;
[SerializeField]
private GameObject workerPrefab = null;
private List<GameObject> houses = new List<GameObject>();
void Start()
{
StartCoroutine("MoveCamera");
StartCoroutine("EndGame");
}
private IEnumerator MoveCamera()
{
while (Camera.main.orthographicSize < 9f) {
Camera.main.orthographicSize += 0.01f;
yield return null;
}
}
private IEnumerator EndGame()
{
float spawnRate = 5f;
int count = 0;
while (count < 9)
{
GameObject go = Instantiate<GameObject>(housePrefab);
houses.Add(go);
go.transform.position = new Vector3(Random.Range(1f, 14f), Random.Range(1f, 14f),-5);
spawnRate -= 0.5f;
yield return new WaitForSeconds(spawnRate);
count++;
}
for (int i = 0; i < 3; i++) {
GameObject go = Instantiate<GameObject>(housePrefab);
houses.Add(go);
go.transform.position = new Vector3(Random.Range(1f, 14f), Random.Range(1f, 14f), -5);
yield return new WaitForSeconds(spawnRate);
}
count = 0;
while (count < 150)
{
GameObject go = Instantiate<GameObject>(workerPrefab);
int index = Random.Range(0, houses.Count);
go.transform.position = houses[index].transform.position;
go.AddComponent<MoveRandomly>();
Destroy(go.GetComponent<Collector>());
Destroy(go.GetComponent<Rigidbody2D>());
yield return new WaitForSeconds(0.1f);
count++;
}
}
}
fileFormatVersion: 2
guid: d3674a5cdecf6e14abe5d88e6f0f7618
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment