void BeamAttack() { GetAnimRig().SetTrigger("Beam"); SlashBehavior beamu = Instantiate(beam); Vector3 offset = Vector2.zero; Vector2 playerPos = GetPlayer().transform.position; if (playerPos.y > transform.position.y && Mathf.Abs(transform.position.y - playerPos.y) < Mathf.Abs(transform.position.x - playerPos.x)) { offset += new Vector3(0, 100, 0); } if (playerPos.y < transform.position.y && Mathf.Abs(transform.position.y - playerPos.y) < Mathf.Abs(transform.position.x - playerPos.x)) { offset += new Vector3(0, -100, 0); } if (playerPos.x > transform.position.x && Mathf.Abs(transform.position.y - playerPos.y) > Mathf.Abs(transform.position.x - playerPos.x)) { offset += new Vector3(0, 100, 0); } if (playerPos.x < transform.position.x && Mathf.Abs(transform.position.y - playerPos.y) > Mathf.Abs(transform.position.x - playerPos.x)) { offset += new Vector3(0, -100, 0); } offset = transform.position + offset; beamu.SetEdges(transform.position, offset); beamu.transform.localScale = new Vector2(Vector2.Distance(transform.position, offset), 1f); beamu.transform.position = new Vector2((transform.position.x + offset.x) / 2, (transform.position.y + offset.y) / 2); beamu.transform.LookAt(transform.position); beamu.transform.rotation = new Quaternion(0, 0, beamu.transform.rotation.z, beamu.transform.rotation.w); }
void SpawnSlash(Vector2 start, Vector2 end) { SlashBehavior slesh = Instantiate(slosh); slesh.SetEdges(start, end); slesh.transform.localScale = new Vector2(Vector2.Distance(start, end), 1f); slesh.transform.position = new Vector2((start.x + end.x) / 2, (start.y + end.y) / 2); slesh.transform.LookAt(start); slesh.transform.rotation = new Quaternion(0, 0, slesh.transform.rotation.z, slesh.transform.rotation.w); }
void Aggressive() { hasBeenSeen = true; if (isScared && !isEscaping) { Passive(); return; } if (!inAir && jumpTimer > jumpGoal) //Jump at or away from the player at a fixed interval { Jump(); } if (slashTimer > slashGoal && slashGoal > 0f) //Slash at the player at a fixed interval if there is in fact an interval { slashTimer = 0f; SlashBehavior slesh = Instantiate(slash); slesh.transform.localScale = new Vector2(Random.Range(1.25f, 2f), 0.3f); //determine X position of slash float playerX = GetPlayer().transform.position.x; float targetX = playerX + Random.Range(-1.5f, 1.5f); while (Mathf.Abs(targetX - playerX) < .5f) { targetX = playerX + Random.Range(-1.5f, 1.5f); } //determine Y position of slash float playerY = GetPlayer().transform.position.y; float targetY = playerY + Random.Range(-1.5f, 1.5f); while (Mathf.Abs(targetY - playerY) < .5f) { targetY = playerY + Random.Range(-1.5f, 1.5f); } slesh.transform.position = new Vector2(targetX, targetY); slesh.transform.Rotate(0, 0, Random.Range(0, 359)); slesh.transform.rotation = new Quaternion(0, 0, slesh.transform.rotation.z, slesh.transform.rotation.w); } jumpTimer += Time.deltaTime; slashTimer += Time.deltaTime; }