// Update is called once per frame void Update() { #region User movement input //translate/rotate float xAxis = Input.GetAxis("Horizontal"); float yAxis = Input.GetAxis("Vertical"); transform.Translate(xAxis * Time.deltaTime * speed, yAxis * Time.deltaTime * speed, 0.0f); //transform.Translate(0.0f, yAxis * Time.deltaTime * speed, 0.0f); //transform.Rotate(transform.forward, - xAxis * Time.deltaTime * turnSpeed); //clamp to world levelBehavior.ClampToWorld(transform, 5.0f); #endregion #region Fire projectile if (Input.GetAxis("Fire1") > 0f) //Left-Control { if (delayCount-- <= 0 && Projectile != null) { GameObject e = Instantiate(Projectile) as GameObject; ProjectileMovement proj = e.GetComponent <ProjectileMovement>(); if (null != proj) { e.transform.position = transform.position; //change projectile direction switch (currentFacing) { case Facing.East: proj.SetForwardDirection(transform.right); break; case Facing.West: proj.SetForwardDirection(-transform.right); break; case Facing.South: proj.SetForwardDirection(-transform.up); break; default: proj.SetForwardDirection(transform.up); break; } } delayCount = recastDelay; } } #endregion //Toggle movement if (Input.GetButtonUp("Jump")) { levelBehavior.Movement = !levelBehavior.Movement; } //Update facing updateFacing(xAxis, yAxis); }
// Update is called once per frame void Update() { #region User movement input //translate/rotate float xAxis = Input.GetAxis("Horizontal"); float yAxis = Input.GetAxis("Vertical"); transform.Translate(xAxis * Time.deltaTime * speed, yAxis * Time.deltaTime * speed, 0.0f); //transform.Translate(0.0f, yAxis * Time.deltaTime * speed, 0.0f); //transform.Rotate(transform.forward, - xAxis * Time.deltaTime * turnSpeed); //clamp to world sceneBoundary.ClampToWorld(transform, 5.0f); #endregion #region Recharge charges //increase number of charges if delay is up and not at max already if (rechargeDelayCount-- <= 0 && charges < MaxCharges) { charges++; rechargeDelayCount = RechargeDelay; //Debug.Log(charges + "/" + MaxCharges); } #endregion #region Fire projectile if (Input.GetAxis("Fire1") > 0f) //Left-Control { //check if recast delay is up, there is a charge, and projectile loaded if (recastDelayCount-- <= 0 && charges > 0 && Projectile != null) { //Debug.Log(charges + "/" + MaxCharges + " " + recastDelayCount + "/" + RecastDelay); charges--; GameObject e = Instantiate(Projectile) as GameObject; ProjectileMovement proj = e.GetComponent <ProjectileMovement>(); if (null != proj) { e.transform.position = new Vector3(transform.position.x, transform.position.y + 2, transform.position.z); //change projectile direction switch (currentFacing) { case Facing.East: proj.SetForwardDirection(transform.right); break; case Facing.West: proj.SetForwardDirection(-transform.right); break; case Facing.South: proj.SetForwardDirection(-transform.up); e.GetComponent <SpriteRenderer>().sortingLayerName = "Player"; //put fireball ontop of player break; default: proj.SetForwardDirection(transform.up); break; } } recastDelayCount = RecastDelay; } } #endregion //Update facing updateFacing(xAxis, yAxis); }