// Update is called once per frame void Update() { if (!paused) { float translateX = Input.GetAxis("Horizontal") * vitesse; if (translateX > 0) { direction = 1; if (!facingRight) { Flip(); } } else if (translateX < 0) { direction = -1; if (facingRight) { Flip(); } } if (Input.GetMouseButtonDown(0)) { HandleClick(leftHand, tentacleAnims.Length > 0 ? tentacleAnims[0] : null); } if (Input.GetMouseButtonDown(1)) { HandleClick(rightHand, tentacleAnims.Length > 1 ? tentacleAnims[1] : null); } if (translateX == 0f) { rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y); anim.Play("Iddle"); } else { footstepSoundacc += Time.deltaTime; rb.velocity = new Vector2(translateX, rb.velocity.y); if (anim.currentAnimation != "Run" && grounded) { anim.Play("Run"); } if (anim.currentAnimation != "DashFwd" && !grounded && (rb.velocity.x > 0 && facingRight || (rb.velocity.x < 0 && !facingRight))) { anim.Play("DashFwd"); } if (anim.currentAnimation != "DashBack" && !grounded && (rb.velocity.x > 0 && !facingRight || (rb.velocity.x < 0 && facingRight))) { anim.Play("DashBack"); } } if (footstepSoundacc > footstepDelay && grounded) { footstepSoundacc = 0; playFootstep(0.3f); } if (Input.GetKeyDown(KeyCode.K)) { die(); } rb.freezeRotation = true; } }
// Update is called once per frame void Update() { BoxCollider2D bc = gameObject.GetComponent <BoxCollider2D> (); if (this.transform.position.x < -6 && onLeft) { GetComponent <SpriteRenderer> ().flipX = true; onLeft = false; } else if (this.transform.position.x > 6 && !onLeft) { GetComponent <SpriteRenderer> ().flipX = false; onLeft = true; } /*if (onLeft) { * rb.velocity = new Vector2 (-1 * vitesse, rb.velocity.y); * } else { * rb.velocity = new Vector2 (1 * vitesse, rb.velocity.y); * }*/ if (tentacleAnim != null && tentacleAnim.IKBase != null) { tentacleAnim.IKBase.transform.position = this.transform.position + new Vector3(Mathf.Cos(Time.time * 1.5f + mode) * 2, Mathf.Sin(Time.time + mode) * 2, 1); tentacleAnim.IKTipOfTentacle.transform.position = this.transform.position + new Vector3(Mathf.Sin(Time.time * 1.5f + mode) * 2.5f, Mathf.Sin(Time.time + mode) * 2.5f, 1); accumulator -= Time.deltaTime; if (accumulator <= 0) { if (mode == 1 && grounded) { Vector2 orientation = (tentacleAnim.IKBase.transform.position - this.transform.position).normalized; rb.AddForce(new Vector2(orientation.x * 200, orientation.y * 200)); Debug.Log("Going toward " + orientation); this.AnimateOverTime01(0.4f, j => { Vector2 destination = (Vector2)transform.position - orientation; tentacleAnim.IKTipOfTentacle.position = Vector3.Lerp( tentacleAnim.IKTipOfTentacle.position, destination, j ); }); } if (mode == 2) { //t = GameObject.Instantiate (attackTentaclePrefab); } if (mode == 3) { // t = GameObject.Instantiate (shieldTentaclePrefab); } accumulator = attackCooldown + attackCooldown * UnityEngine.Random.Range(0, 1); } } if (grounded && mode == 1) { rb.freezeRotation = true; } if (rb.velocity.magnitude < 0.1f) { if (animation.currentAnimation != "Iddle") { animation.Play("Iddle"); } } else { if (animation.currentAnimation != "Run") { animation.Play("Run"); } } if (life.GetHp() <= 0) { life.SetHp(0); Die(); } }