void CreateLoot() { if (FindObjectOfType <FlipPlayer>().goingUp) { return; } if (Random.Range(0, 5) != 0) { return; /* Changing problability */ } int newLootType = Random.Range(0, LootDemo.Length * 2 - 1); newLootType = newLootType / 2; newLoot = Instantiate(LootDemo[newLootType]); LootBehaviour newBehaviour = newLoot.GetComponent <LootBehaviour>(); newBehaviour.velocity = new Vector2(0, 300 + (100 * Random.Range(0.0f, 1.0f))); Vector3 newPosition = LootDemo[newLootType].transform.position; newPosition[0] = Screen.width / 2 * Random.Range(-0.9f, 0.9f); newLoot.transform.position = newPosition; // loots[lootCount++] = newLoot; }
IEnumerator FireCoroutine(Vector3 direction) { firing = true; moveTimer = 0f; subStartingPosition = subPosition(); float angle = Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x) - 90f; transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle)); transform.position = subStartingPosition + direction * startDistance; renderer.enabled = true; line.enabled = true; transform.parent = null; audio.PlayOneShot(fireSound); grappleParticles.Emit(20); // move out while (moveTimer < moveTime && currentLoot == null) { transform.position += direction * moveSpeed * Time.deltaTime; moveTimer += Time.deltaTime; yield return null; } Vector3 farthestPosition = transform.position; float maxTimer = moveTimer; while (moveTimer > 0f) { transform.position = Vector3.Lerp(farthestPosition, subPosition(), 1f - moveTimer / maxTimer); moveTimer -= Time.deltaTime; if ((transform.position - subStartingPosition).magnitude < startDistance) { break; } yield return null; } firing = false; moveTimer = 0f; renderer.enabled = false; line.enabled = false; if (currentLoot != null) { lootCounter.addLoot(currentLoot.getValue()); Destroy(currentLoot.gameObject); currentLoot = null; } }
private void attachLoot(LootBehaviour loot) { this.currentLoot = loot; loot.attachTo(transform); audio.PlayOneShot(lootSound); }
// Use this for initialization void Start() { currentLoot = null; firing = false; renderer.enabled = false; line = GetComponent<LineRenderer>(); line.SetVertexCount(2); }