void FixedUpdate() { if (!paused) { if (moveUpAmount >= .35f) { MoveLeftRight(); } RotateLeftRight(); if (moveUpAmount >= -.1f) { movePosition.y += moveUpAmount; transform.position = movePosition; moveUpAmount -= moveUpAmount / 50; } if (moveUpAmount <= .5f) { timedDestroy += Time.fixedDeltaTime; text.CrossFadeAlpha(0f, .25f, false); if (timedDestroy >= .4f) { Pooling.Despawn(gameObject); timedDestroy = 0; moveUpAmount = startMoveUpAmount; moveLeftRightAmount = Random.value + Random.value; rotation.z = 0; } } } }
protected override void OnTriggerEnter2D(Collider2D col) { //Override Shotclass trigger enter if (col.tag.Equals("Ground") && attacked) { attacked = false; attackWait = startAttackwait; timeAlive = startTimeAlive; Pooling.Despawn(gameObject); } }
private void SpawnStalags() { randSpawn = new Vector2(Random.Range(-1, 13) + Random.value, Random.Range(8, 10) + Random.value); GameObject clone = (GameObject)Pooling.Spawn(stalag, randSpawn, Quaternion.identity); clone.GetComponent <ShotClass>().SetPrefabValues(); clone.GetComponent <Rigidbody2D>().velocity = Vector2.zero; attacked = false; timeAlive = startTimeAlive; Pooling.Despawn(gameObject); }
protected void CheckTime() { if (timeAlive > 0) { timeAlive -= Time.deltaTime; } else if (timeAlive <= 0) //If the fired shot is alive for longer than timeAlive, we destroy it { timeAlive = startTimeAlive; velocity = Vector2.zero; rigbod.velocity = Vector2.zero; Pooling.Despawn(gameObject); } }
private void SpawnLava() { randSpawn = new Vector2(Random.Range(-1, 13) + Random.value, Random.Range(-7, -5) + Random.value); Vector3 spawnRotation = new Vector3(0, 0, 90); GameObject clone = (GameObject)Pooling.Spawn(lava, randSpawn, Quaternion.Euler(spawnRotation)); clone.GetComponent <Rigidbody2D>().velocity = Vector2.zero; LavaBolt tempLavaBolt = clone.GetComponent <LavaBolt>(); tempLavaBolt.moveTimer = 0; tempLavaBolt.stopMove = false; tempLavaBolt.justSpawned = true; clone.GetComponent <ShotClass>().SetPrefabValues(); attacked = false; timeAlive = startTimeAlive; Pooling.Despawn(gameObject); }
private void Move() { movePosition.y += moveUpAmount; moveUpAmount -= moveUpAmount / 50; if (moveUpAmount <= .5f) { timedDestroy += Time.fixedDeltaTime; text.CrossFadeAlpha(0f, .35f, false); if (timedDestroy >= .5f) { Pooling.Despawn(gameObject); timedDestroy = 0; moveUpAmount = startMoveUpAmount; } } transform.position = movePosition; }
// Update is called once per frame void Update() { //With speed = 1, the obj will translate 1 Unity unit each second if (triggerMovement) { Vector3 pos = gameObject.transform.position; //If the obstacle is out of the screen if (pos.x <= endPoint.position.x) { pool.Despawn(gameObject); triggerMovement = false; } else { pos.x -= Time.deltaTime * speed; gameObject.transform.position = pos; } } }
private void DespawnThis() { ResetValues(); UpdateHealthBar(); Pooling.Despawn(gameObject); }
void UpdateDragging() { if (Input.GetMouseButtonDown(0)) { dragStartPosition = currFramePosition; } int start_x = Mathf.FloorToInt(dragStartPosition.x); int end_x = Mathf.FloorToInt(currFramePosition.x); int start_y = Mathf.FloorToInt(dragStartPosition.y); int end_y = Mathf.FloorToInt(currFramePosition.y); if (end_x < start_x) { int tmp = end_x; end_x = start_x; start_x = tmp; } if (end_y < start_y) { int tmp = end_y; end_y = start_y; start_y = tmp; } while (dragPreviewGameObjects.Count > 0) { GameObject go = dragPreviewGameObjects[0]; dragPreviewGameObjects.RemoveAt(0); Pooling.Despawn(go); } if (Input.GetMouseButton(0)) { for (int x = start_x; x <= end_x; x++) { for (int y = start_y; y <= end_y; y++) { Tile t = WorldController.Instance.World.GetTileAt(x, y); if (t != null) { GameObject go = Pooling.Spawn(circleCursorPrefab, new Vector3(x, y, 0), Quaternion.identity); go.transform.SetParent(this.transform, true); dragPreviewGameObjects.Add(go); } } } } if (Input.GetMouseButtonUp(0)) { for (int x = start_x; x <= end_x; x++) { for (int y = start_y; y <= end_y; y++) { Tile t = WorldController.Instance.World.GetTileAt(x, y); if (t != null) { t.Type = Tile.TileType.Floor; } } } } }