private HealthBar healthBar; // SerializeField : à quoi ça sert? // Start is called before the first frame update private void Start() { float health = 1f; //From CodeMonkey.Utils // 0.03f : timer FunctionPeriodic.Create(() => { if (health > 0.005f) { //Reduce health health -= 0.005f; healthBar.SetSize(health); if (health < .3f) { //Under 30 % => alternate between white and red int health_int = Mathf.FloorToInt(health * 100f); if (health_int % 3 == 0) { healthBar.SetColor(Color.white); } else { healthBar.SetColor(Color.red); } } } }, .01f); }
private void Start() { float health = 1f; FunctionPeriodic.Create(() => { if (health > .01f) { health -= .01f; healthBar.SetSize(health); if (health < .3f) { // Under 30% health if ((int)(health * 100f) % 3 == 0) { healthBar.SetColor(Color.white); } else { healthBar.SetColor(Color.red); } } } else { health = 1f; healthBar.SetColor(Color.red); } }, .05f); }
public void SetUp(Snake snake) { this.snake = snake; SpawnFood(); FunctionPeriodic.Create(SpawnFood, 1f); }
private void Start() { FunctionPeriodic.Create(() => { float startTime = Time.realtimeSinceStartup; if (!useJobs) { for (int i = 0; i < 5; i++) { FindPath(new int2(0, 0), new int2(19, 19)); } } else { int findPathJobCount = 5; NativeArray <JobHandle> jobHandleArray = new NativeArray <JobHandle>(findPathJobCount, Allocator.Temp); for (int i = 0; i < findPathJobCount; i++) { FindPathJob findPathJob = new FindPathJob { startPosition = new int2(0, 0), endPosition = new int2(19, 19) }; jobHandleArray[i] = findPathJob.Schedule(); } JobHandle.CompleteAll(jobHandleArray); jobHandleArray.Dispose(); } Debug.Log("Time: " + ((Time.realtimeSinceStartup - startTime) * 1000f)); }, 1f); }
// Start is called before the first frame update void Start() { Instance = this; currentTarget = GetNewRandomPosition(); rb = GetComponent <Rigidbody2D>(); rb.mass = UnityEngine.Random.Range(0.2f, 0.5f); cameraHeight = 2f * Camera.main.orthographicSize; cameraWidth = cameraHeight * Camera.main.aspect; lastFacingPosition = Vector2.zero; xBaseTransform = Math.Abs(transform.localScale.x); if (DamageZone.instance != null) { FunctionPeriodic.Create(() => { if (DamageZone.instance.IsOutsideCircle(transform.position)) { Damage(); } }, .5f); } animator = GetComponent <Animator>(); }
private void Start() { playSound = GetComponent <AudioSource>(); health = 1f; FunctionPeriodic.Create(() => { if (health > .01f) { health -= .001f; healthBar.SetSize(health); if (health < .3f) { if ((health * 100f) % 3 == 0) { healthBar.SetColor(Color.white); } else { healthBar.SetColor(Color.red); } } } }, 0.03f); }
/** * Spawn armor potions in the area */ private void SpawnArmorPotions() { FunctionPeriodic.Create( () => { if (IngestibleManager.IngestibleCount <ArmorPotion>() < _ARMOR_POTION_MAX_SPAWNS) { Vector3 armorPotionWorldPosition = new Vector3( Random.Range(-_MAX_RADIUS, _MAX_RADIUS), AssetManager.Get_Prefab_ArmorPotion().transform.localScale.y / 2 + AssetManager.GetTerrain().localScale.y, Random.Range(-_MAX_RADIUS, _MAX_RADIUS) ); ArmorPotion armorPotion = Instantiate( AssetManager.Get_Prefab_ArmorPotion(), armorPotionWorldPosition, Quaternion.identity ); IngestibleManager.AddIngestible(armorPotion); } }, "SpawnArmorPotions", 0f, 0f, () => { if (IngestibleManager.IngestibleCount <ArmorPotion>() >= _ARMOR_POTION_MAX_SPAWNS) { Destroy(GameObject.Find("SpawnArmorPotions")); } } ); }
/** * Spawn some clouds in the air */ private void SpawnClouds() { FunctionPeriodic.Create( () => { if (EnvironmentManager.ComponentCount <Cloud>() < _CLOUD_MAX_SPAWNS) { Vector3 cloudWorldPosition = new Vector3( _SPAWN_CLOUD_X, 0f, Random.Range(-_MAX_RADIUS, _MAX_RADIUS) ); Cloud cloud = Instantiate( AssetManager.Get_Prefab_Cloud(), cloudWorldPosition, Quaternion.identity ); EnvironmentManager.AddComponent(cloud); } }, "SpawnClouds", 0f, 0f ); }
/** * Spawn some birds in the air */ private void SpawnBirds() { FunctionPeriodic.Create( () => { if (EnvironmentManager.ComponentCount <Bird>() < _BIRD_MAX_SPAWNS) { Vector3 birdWorldPosition = new Vector3( _SPAWN_BIRD_X, 0f, Random.Range(-_MAX_RADIUS, _MAX_RADIUS) ); Bird bird = Instantiate( AssetManager.Get_Prefab_Bird(), birdWorldPosition, Quaternion.identity ); EnvironmentManager.AddComponent(bird); } }, "SpawnBirds", 0f, 0f ); }
// Persist through scene loads public static FunctionPeriodic Create_Global(Action action, Func <bool> testDestroy, float timer) { FunctionPeriodic functionPeriodic = Create(action, testDestroy, timer, "", false, false, false); MonoBehaviour.DontDestroyOnLoad(functionPeriodic.gameObject); return(functionPeriodic); }
private void Start() { cameraFollow.Setup(GetCameraPosition, () => 90f, true, true); FunctionPeriodic.Create(SpawnEnemy, 2f); EnemyHandler.Create(new Vector3(20, 0)); characterAimHandler.OnShoot += CharacterAimHandler_OnShoot; }
private void StartBattle() { MusicManager.Instance.PlayMusic(MusicManager.MusicTheme.Boss); SpawnBoss(); StartNextStage(); FunctionPeriodic.Create(SpawnEnemy, _spawnEnemyTime, "enemySpawn"); FunctionPeriodic.Create(SpawnHealthPickup, _healthPickupSpawnTime, "spawnHealthPickup"); }
public void PeriodicallyChangeStatBar(StatBar statBar, float time, float quantity) { FunctionPeriodic.Create(() => { if (statBar.GetValue() > 0f) { statBar.AddValue(quantity); } }, time); }
// Start is called before the first frame update void Start() { Debug.Log("console: GameHandler.Start"); int i = 0; FunctionPeriodic.Create(() => { CMDebug.TextPopupMouse("Ding " + i + "!"); i++; }, .5f); }
private void Turret_OnDead(object sender, System.EventArgs e) { Debug.Log("Boss dead!"); FunctionPeriodic.StopAllFunc("BossSpawnEnemy"); FunctionPeriodic.StopAllFunc("BossSpawnEnemy_2"); FunctionPeriodic.StopAllFunc("BossSpawnHealthPickup"); DestroyAllEnemies(); keyGameObject.SetActive(true); }
private void Awake() { icon = transform.Find("Icon").GetComponent <SpriteRenderer>(); amount = transform.Find("Amount").GetComponent <TextMeshPro>(); FunctionPeriodic.Create(() => { Destroy(this.gameObject); }, 300); FindObjectOfType <InputController>().onInteract += OnInteract; }
// Start is called before the first frame update void Start() { // Get Unity Components rb = GetComponent <Rigidbody2D>(); pS = FindObjectOfType <proceduralSpawning>(); // Periodic function for recharging the coil FunctionPeriodic.Create(() => { energyRecharge(); }, 0.1f); }
private void Start() { enemyHandlerList = new List <EnemyHandler>(); playerHandler = PlayerHandler.CreatePlayer(GetClosestEnemyHandler); playerHandler.OnDead += delegate(object sender, EventArgs e) { Window_GameOver.Show(); }; cameraFollow.Setup(70f, 2f, playerHandler.GetPosition); FunctionPeriodic.Create(SpawnEnemy, 1.5f); }
private void BossBattle_OnDead(object sender, System.EventArgs e) { // Turret dead! Boss battle over! Debug.Log("Boss Battle Over!"); FunctionPeriodic.StopAllFunc("spawnEnemy"); FunctionPeriodic.StopAllFunc("spawnEnemy_2"); FunctionPeriodic.StopAllFunc("spawnHealthPickup"); DestroyAllEnemies(); OnBossBattleOver?.Invoke(this, EventArgs.Empty); }
private void TestTooltip() { ShowTooltip("Testing tooltip..."); FunctionPeriodic.Create(() => { string abc = "qwertyuioplkjhgffdssaZX,CMBVBSDF"; string text = "Testing tooltip..."; for (int i = 0; i < UnityEngine.Random.Range(5, 100); i++) { text += abc[UnityEngine.Random.Range(0, abc.Length)]; } ShowTooltip(text); }, .5f); }
private void Awake() { instance = this; // Grab base objects references graphContainer = transform.Find("graphContainer").GetComponent <RectTransform>(); labelTemplateY = graphContainer.Find("labelTemplateY").GetComponent <RectTransform>(); startYScaleAtZero = true; gameObjectList = new List <GameObject>(); yLabelList = new List <RectTransform>(); graphVisualObjectList = new List <IGraphVisualObject>(); IGraphVisual lineGraphVisual = new LineGraphVisual(graphContainer, dotSprite, Color.green, new Color(1, 1, 1, .5f)); // Set up base values List <int> valueList = new List <int>() { 0, 0 }; ShowGraph(valueList, lineGraphVisual, -1, (int _i) => "Day " + (_i + 1), (float _f) => Mathf.RoundToInt(_f).ToString()); /* * // Automatically modify graph values and visual * bool useBarChart = true; * FunctionPeriodic.Create(() => { * for (int i = 0; i < valueList.Count; i++) { * valueList[i] = Mathf.RoundToInt(valueList[i] * UnityEngine.Random.Range(0.8f, 1.2f)); * if (valueList[i] < 0) valueList[i] = 0; * } * if (useBarChart) { * ShowGraph(valueList, barChartVisual, -1, (int _i) => "Day " + (_i + 1), (float _f) => "$" + Mathf.RoundToInt(_f)); * } else { * ShowGraph(valueList, lineGraphVisual, -1, (int _i) => "Day " + (_i + 1), (float _f) => "$" + Mathf.RoundToInt(_f)); * } * useBarChart = !useBarChart; * }, .5f); * //*/ int index = 0; FunctionPeriodic.Create(() => { //int index = UnityEngine.Random.Range(0, valueList.Count); //UpdateValue(index, valueList[index] + UnityEngine.Random.Range(1, 3)); addValue(GameLogic.instance.infectedCount); ShowGraph(valueList, lineGraphVisual, valueList.Count, (int _i) => "Day " + (_i + 1), (float _f) => Mathf.RoundToInt(_f).ToString()); }, 10f); }
private void Start() { //Sound_Manager.Init(); cameraFollow.Setup(GetCameraPosition, () => 60f, true, true); FunctionPeriodic.Create(SpawnEnemy, 1.5f); gridPathfinding = new GridPathfinding(new Vector3(-400, -400), new Vector3(400, 400), 5f); gridPathfinding.RaycastWalkable(); EnemyHandler.Create(new Vector3(20, 0)); characterAimHandler.OnShoot += CharacterAimHandler_OnShoot; }
private void StartNextStage() { switch (stage) { case Stage._0: stage = Stage._1; stage_1.SetActive(true); FunctionTimer.Create(SpawnEnemy, 1f); FunctionTimer.Create(SpawnEnemy, 3f); SpawnEnemy(); SpawnEnemy(); SpawnPickup(); break; case Stage._1: stage = Stage._2; stage_2.SetActive(true); FunctionPeriodic.Create(SpawnEnemy, 4f, "BossSpawnEnemy"); FunctionTimer.Create(SpawnHealthPickup, 4f); FunctionTimer.Create(SpawnEnemy, 0.1f); FunctionTimer.Create(SpawnEnemy, 0.5f); FunctionTimer.Create(SpawnEnemy, 5.0f); FunctionTimer.Create(SpawnEnemy, 8.0f); FunctionPeriodic.Create(SpawnPickup, 5f, "BossSpawnHealthPickup"); SpawnEnemy(); SpawnPickup(); break; case Stage._2: stage = Stage._3; stage_2.SetActive(false); stage_3.SetActive(true); FunctionPeriodic.Create(SpawnEnemy, 6f, "BossSpawnEnemy_2"); FunctionTimer.Create(SpawnEnemy, 0.1f); FunctionTimer.Create(SpawnEnemy, 0.5f); FunctionTimer.Create(SpawnEnemy, 1.0f); FunctionTimer.Create(SpawnEnemy, 1.5f); FunctionTimer.Create(SpawnEnemy, 5.0f); FunctionTimer.Create(SpawnEnemy, 8.5f); FunctionTimer.Create(SpawnEnemy, 10.0f); FunctionTimer.Create(SpawnEnemy, 11.0f); FunctionTimer.Create(SpawnEnemy, 12.0f); SpawnPickup(); SpawnPickup(); break; } }
private void Start() { scoreComparer = new ScoreComparer(); spritesArray = new Sprite[] { empty, mine1, mine2, mine3, mine4, mine5, mine6, mine7, mine8, mine, flag, covered, }; switch (MenuScript.level) { case 2: map = new Map(15, 20, transform.position, parent); break; case 3: map = new Map(30, 21, transform.position, parent); break; default: map = new Map(10, 10, transform.position, parent); break; } transform.Find("GameOverScreen").gameObject.SetActive(false); transform.Find("WinnerScreen").gameObject.SetActive(false); transform.Find("HighScoreAchievedScreen").gameObject.SetActive(false); timer = transform.Find("CanvasTimer").Find("SecondsText").GetComponent <TMP_Text>(); int secs = Convert.ToInt32(timer.text); FunctionPeriodic.Create(() => { if (transform.Find("GameOverScreen").gameObject.activeSelf || transform.Find("WinnerScreen").gameObject.activeSelf) { return; } secs++; timer.text = secs + ""; }, 1f); }
private void Start() { Debug.Log("GameHandler.Start"); int number = 0; FunctionPeriodic.Create(() => { CMDebug.TextPopupMouse("Don't work with this lady! She a ssssnake"); number++; }, .5f); levelGrid = new LevelGrid(20, 20); snake.SetUp(levelGrid); levelGrid.SetUp(snake); }
private Tower(Transform towerTransform, Action onTowerConstructedAction) { this.towerTransform = towerTransform; this.onTowerConstructedAction = onTowerConstructedAction; spriteRenderer = towerTransform.GetComponent <SpriteRenderer>(); spriteRenderer.sprite = GameAssets.i.towerConstruction_1; constructionTick = 0; constructionTickMax = 10; FunctionPeriodic.Create(IncreaseConstructionTick, .5f); constructionBar = new World_Bar(towerTransform, new Vector3(0, -5), new Vector3(10, 1.5f), null, Color.yellow, 0f, 0, new World_Bar.Outline { color = Color.black, size = 1f }); }
private void Start() { FunctionPeriodic.Create(HealingAnimatedPeriodic, .05f); HeartsHealthSystem heartsHealthSystem = new HeartsHealthSystem(5); SetHeartsHealthSystem(heartsHealthSystem); //Testing buttons CMDebug.ButtonUI(new Vector2(-50, -100), "Damage 1", () => heartsHealthSystem.Damage(1)); CMDebug.ButtonUI(new Vector2(50, -100), "Damage 4", () => heartsHealthSystem.Damage(4)); CMDebug.ButtonUI(new Vector2(-50, -200), "Heal 1", () => heartsHealthSystem.Heal(1)); CMDebug.ButtonUI(new Vector2(50, -200), "Heal 4", () => heartsHealthSystem.Heal(4)); CMDebug.ButtonUI(new Vector2(150, -200), "Heal 50", () => heartsHealthSystem.Heal(50)); }
private void BossBattle_OnDeath(object sender, System.EventArgs e) { // Boss dead! Boss battle over! Debug.Log("Boss Battle Over!"); FunctionPeriodic.StopAllFunc("enemySpawn"); FunctionPeriodic.StopAllFunc("spawnHealthPickup"); FunctionPeriodic.StopAllFunc("spawnShieldPickup"); DestroyAllEnemies(); if (!m_IsFinalBoss) { MusicManager.Instance.PlayMusic(MusicManager.MusicTheme.Game); } OnBossDeath?.Invoke(this, EventArgs.Empty); }
// Start is called before the first frame update void Start() { uS = FindObjectOfType <upgradeSystem>(); InvokeRepeating("updateTarget", 0f, 0.5f); // Periodic function for FunctionPeriodic.Create(() => { if ((uS.hasMiniCoil == true) && (targetLocked != null)) { miniCoilAggro(); } }, 60f / miniCoilFireRate); }
private void Start() { ChatBubble.Create(playerTransform, new Vector3(3, 8), ChatBubble.IconType.Neutral, "Here is some text!"); FunctionPeriodic.Create(() => { Transform npcTransform = npcTransformArray[npcIndex]; npcIndex = (npcIndex + 1) % npcTransformArray.Length; string message = GetRandomMessage(); ChatBubble.IconType[] iconArray = new ChatBubble.IconType[] { ChatBubble.IconType.Happy, ChatBubble.IconType.Neutral, ChatBubble.IconType.Angry }; ChatBubble.IconType icon = iconArray[Random.Range(0, iconArray.Length)]; ChatBubble.Create(npcTransform, new Vector3(3, 8), icon, message); }, 1.5f); }