private void attack(Vector2 mouse) { if (actionMap.ready(ATTACK)) { gunAudio.PlayOneShot(shootSound, 0.5f); ++shotsFired; actionMap.use(ATTACK, null); GameObject shot = Instantiate(bulletObj); shot.transform.position = gun.position; shot.transform.rotation = gun.rotation; int WALL_MASK = 1 << 10; float shotRange = 15f; RaycastHit2D hit = Physics2D.Raycast(gun.position, gun.right, shotRange, WALL_MASK); if (hit.collider != null) { shotRange = hit.distance; } shot.transform.localScale = new Vector3(shotRange, 1f, 1f); /* * GameObject expl = Instantiate(explosionObj); * expl.transform.position = mouse; * float ERAD = 0.8f; * foreach (Enemy e in Scene.getEnemies()) { * if ((mouse - (Vector2) e.transform.position).sqrMagnitude < ERAD * ERAD) { * e.damage(1f); * } * } */ } }
// Update is called once per frame void Update() { actionMap.update(Time.deltaTime); if (actionMap.ready(0)) { actionMap.use(0, null); //Scene.echo(transform.position, 4f, 2f, 32); } }
public void FixedUpdate() { //var rb = GetComponent<Rigidbody2D>(); //rb.velocity = transform.up * MAXV; if (target != null) { var delta = target.transform.position - transform.position; var dist = delta.magnitude; if (!hasWayPoint && dist > (2 + DIST_PER_WAYPOINT)) { var randomRotation = Quaternion.AngleAxis(Random.Range(-35f, 35f), Vector3.forward); wayPoint = transform.position + DIST_PER_WAYPOINT * (randomRotation * delta.normalized); hasWayPoint = true; } if (hasWayPoint) { seek(wayPoint); // Check if the alien is as close to the destination as the waypoint is. if ((target.transform.position - wayPoint).magnitude + 0.1f >= dist) { hasWayPoint = false; } } if (!hasWayPoint && dist < 2) { if (actionMap.ready(ATTACK)) { actionMap.use(ATTACK, null); target.GetComponent <Planet>().damage(1); } flee(target); } else { seek(target); } } actionMap.update(Time.fixedDeltaTime); base.FixedUpdate(); }
public bool canAttack() { return(!canTrade() && actionMap.ready(ATTACK) && !statusMap.has(State.ANIMATION)); }