protected override void GetOtherInput() { if (Input.GetButton("Fire1")) { attack_tool = true; } if (!Input.GetButton("Fire1") && attack_tool) { attack_tool = false; } if (Input.GetButton("Fire2") && Time.time > next_attack_iclicker && iclicker.activeSelf) { attack_iclicker = true; next_attack_iclicker += attack_rate_iclicker; GameObject instance = Instantiate(iclicker_attack, spawnPos.position, Quaternion.identity) as GameObject; AttackMover script = instance.GetComponent <AttackMover> (); script.direction = Vector2.right; } if (!Input.GetButton("Fire2") && attack_iclicker && iclicker.activeSelf) { attack_iclicker = false; } if (gc.score == 0) { die = true; } if (transform.position.y <= -25f) { die = true; } animator.SetBool("Die", die); animator.SetBool("AttackTool", attack_tool); animator.SetBool("Die", die); animator.SetBool("AttackIclicker", attack_iclicker); }
void Update() { Vector2 distance = player.transform.position - transform.position; direction = distance; if (distance.sqrMagnitude < distance_lim_square && Time.time > next_attack) { next_attack += attack_rate; float rand_num = Random.value; GameObject to_instantiate = attack_one; if (rand_num > 0.5) { to_instantiate = attack_two; } //flip sprite to the side facing the player float dot = -player.transform.position.x * transform.position.y + player.transform.position.y * transform.position.x; if (dot < 0 && !spriteRenderer.flipX) { spriteRenderer.flipX = true; //spawnPos.transform.position = initialSpawnPos; } else if (dot > 0 && spriteRenderer.flipX) { spriteRenderer.flipX = false; //spawnPos.transform.position = -10*initialSpawnPos; } GameObject instance = Instantiate(to_instantiate, spawnPos.position, Quaternion.identity) as GameObject; AttackMover script = instance.GetComponent <AttackMover> (); script.direction = distance / distance.magnitude; //flips back after attack if (dot > 0 && spriteRenderer.flipX) { spriteRenderer.flipX = false; //spawnPos.transform.position = -10*initialSpawnPos; } else if (dot < 0 && !spriteRenderer.flipX) { spriteRenderer.flipX = true; //spawnPos.transform.position = initialSpawnPos; } } if (!spriteRenderer.flipX && transform.position.x < boundary.xMax) { rb.velocity = Vector2.right * move_speed; } if (!spriteRenderer.flipX && transform.position.x >= boundary.xMax) { rb.velocity = Vector2.zero; spriteRenderer.flipX = true; //spawnPos.transform.position = initialSpawnPos; } if (spriteRenderer.flipX && transform.position.x > boundary.xMin) { rb.velocity = Vector2.left * move_speed; } if (spriteRenderer.flipX && transform.position.x <= boundary.xMin) { rb.velocity = Vector2.zero; spriteRenderer.flipX = false; //spawnPos.transform.position = -10*initialSpawnPos; } }