// Update is called once per frame void Update() { if (target == null) { target = GameObject.FindGameObjectWithTag("player"); distance_to_player = GetDistanceSquared(target); } // try to make signed integers for bit fun! :D float directionX; if (this.gameObject.transform.position.x > target.transform.position.x) { directionX = -1; } else { directionX = 1; } if (distance_to_player <= range_squared && atk_delay_frames == 0.0f) { hitbox = Instantiate(Resources.Load("Hitbox"), source) as GameObject; hitbox.transform.position = new Vector2( this.gameObject.transform.position.x + atk_offset * directionX, this.gameObject.transform.position.y ); Hitbox_Controller hc = hitbox.GetComponent <Hitbox_Controller>(); hc.width = atk_width; hc.height = atk_height; hc.damage = damage; hc.knockbackForce = knockback_force; hc.kbDirection = new Vector2(directionX, 1); atk_delay_frames = initial_delay; } else if (!(atk_delay_frames <= 0f)) { atk_delay_frames -= 1.0f; } distance_to_player = GetDistanceSquared(target); }
// Update is called once per frame void Update() { if (canAttack && Input.GetMouseButtonDown(0)) { hitbox = Instantiate(Resources.Load("Hitbox"), source) as GameObject; hitbox.transform.position = new Vector3( transform.position.x + (atk_offset * GetComponent <PlayerMovement>().facingRight), transform.position.y, 0 ); Hitbox_Controller hc = hitbox.GetComponent <Hitbox_Controller>(); hc.width = atk_width; hc.height = atk_height; hc.damage = damage; hc.knockbackForce = knockback_force; hc.kbDirection = new Vector2(GetComponent <PlayerMovement>().facingRight, 1); atk_delay_frames = initial_delay; } }