// Use this for initialization void Start() { life = GetComponent <LifebarController> (); rb = gameObject.GetComponent <Rigidbody2D> (); animation = GetComponent <SelfAnimated> (); tentacle.SetActive(false); GameObject t = null; if (mode == 1) { t = GameObject.Instantiate(dashTentaclePrefab); } if (mode == 2) { t = GameObject.Instantiate(attackTentaclePrefab); } if (mode == 3) { t = GameObject.Instantiate(shieldTentaclePrefab); } if (t != null) { t.transform.parent = this.transform; t.GetComponent <TentacleMouseControl> ().enabled = false; tentacleAnim = t.GetComponent <TentacleAnimation> (); tentacleAnim.BuildTentacle(); t.transform.localPosition = Vector3.zero; t.transform.localScale = Vector3.one; } }
public void handleDash(TentacleAnimation tentacleAnim) { if (!canJump) { return; } Vector2 mouse = Input.mousePosition; mouse = (Vector2)Camera.main.ScreenToWorldPoint(mouse); RaycastHit2D ray = Physics2D.Linecast(transform.position, mouse, 1 << LayerMask.NameToLayer("Default")); Collider2D coll = ray.collider; Transform ikTarget = tentacleAnim.IKTipOfTentacle; this.AnimateOverTime01(0.3f, j => { Vector2 destination = (Vector2)transform.position + (mouse - (Vector2)this.transform.position).normalized * attackDistance; ikTarget.position = Vector3.Lerp( ikTarget.position, destination, j ); }); if (coll != null) { if (coll.gameObject.layer == LayerMask.NameToLayer("Default")) { if (ray.distance < 3) { tentacleAnim.PlayHitSound(0.2f); Vector2 v = ((Vector2)transform.position - mouse).normalized; rb.AddForce(v * jumpHeight); } } else { tentacleAnim.PlayAnimSound(0.1f); } if (coll.gameObject.tag == "alien") { if (ray.distance < 3) { //repousse l'alien et damage Vector2 v = (mouse - (Vector2)transform.position).normalized; coll.gameObject.GetComponent <Rigidbody2D>().AddForce(v * dashKnockBackForce); coll.gameObject.GetComponent <LifebarController>().AddHp(-dashDamage); } } } else { tentacleAnim.PlayAnimSound(0.1f); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); TentacleAnimation myScript = (TentacleAnimation)target; if (GUILayout.Button("Build Tentacle")) { myScript.BuildTentacle(); } }
public void handleGun(TentacleAnimation tentacleAnim) { Vector2 mouse = Input.mousePosition; mouse = (Vector2)Camera.main.ScreenToWorldPoint(mouse); Vector3 orientation = (mouse - (Vector2)this.transform.position).normalized; GameObject shoot = (GameObject)GameObject.Instantiate(shot, this.transform.position + orientation, Quaternion.identity); shoot.GetComponent <Rigidbody2D>().AddForce(orientation * 1000); tentacleAnim.PlayAnimSound(0.1f); //shoot.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000 * direction, 0)); }
public void handleShield(TentacleAnimation tentacleAnim) { if (!hasShield) { return; } if (shieldSpawned) { return; } Vector2 mouse = Input.mousePosition; mouse = (Vector2)Camera.main.ScreenToWorldPoint(mouse); Transform ikTarget = tentacleAnim.IKTipOfTentacle; Transform ikbaseTarget = tentacleAnim.IKBase; tentacleAnim.PlayAnimSound(0.5f); this.AnimateOverTime01(anticipationDuration, i => { ikTarget.position = Vector3.Lerp( ikTarget.position, transform.position + new Vector3(0, 0.2f, 0), i ); ikbaseTarget.position = Vector3.Lerp( ikbaseTarget.position, transform.position, i ); if (i == 1) { Vector2 v = (mouse - (Vector2)transform.position).normalized; GameObject shieldSpawner = (GameObject)GameObject.Instantiate(shieldSpawn, transform.position + (Vector3)v * 2, Quaternion.Euler(0, 0, v.y > 0 ? Vector2.Angle(Vector2.right, v) : Vector2.Angle(Vector2.left, v))); shieldSpawner.transform.parent = this.transform; shieldSpawner.transform.localScale = Vector3.one * 4; shieldSpawned = true; tentacleAnim.PlayHitSound(0.5f); this.AnimateOverTime01(0.4f, j => { ikTarget.position = transform.position + new Vector3(0, 0.2f, 0); ikbaseTarget.position = Vector3.Lerp( ikbaseTarget.position, shieldSpawner.transform.position, i * 2 ); }); } }); }
public void handleTentacle(TentacleAnimation tentacleAnim) { if (!hasTentacle) { return; } Transform ikTarget = tentacleAnim.IKTipOfTentacle; this.AnimateOverTime01(anticipationDuration, i => { ikTarget.position = Vector3.Lerp( ikTarget.position, transform.position, i ); if (i == 1) { tentacleAnim.PlayAnimSound(0.2f); this.AnimateOverTime01(actionDuration, j => { Vector2 mouse = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 destination = (Vector2)transform.position + (mouse - (Vector2)this.transform.position).normalized * attackDistance; ikTarget.position = Vector3.Lerp( ikTarget.position, destination, j ); if (j == 1) { Debug.DrawLine(transform.position, destination); RaycastHit2D ray = Physics2D.Linecast(transform.position, destination, 1 << LayerMask.NameToLayer("Default")); Collider2D coll = ray.collider; if (coll != null) { tentacleAnim.PlayHitSound(0.4f); Debug.Log(coll.gameObject.tag); if (coll.gameObject.tag == "alien") { Vector2 v = (mouse - (Vector2)transform.position).normalized; coll.gameObject.GetComponent <Rigidbody2D>().AddForce(v * dashKnockBackForce); coll.gameObject.GetComponent <LifebarController>().AddHp(-attackDamage); } } } }); } }); }
private void HandleClick(EquipHand hand, TentacleAnimation tentacleAnim) { switch (hand) { case EquipHand.GUN: handleGun(tentacleAnim); break; case EquipHand.DASH: handleDash(tentacleAnim); break; case EquipHand.TENTACLE: handleTentacle(tentacleAnim); break; case EquipHand.SHIELD: handleShield(tentacleAnim); break; } }
public void Update() { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 basePos = basePosition.position; basePos.y += (mousePosition.y < basePos.y) ? 1.0f : +1.0f; float angle = Vector2.SignedAngle(basePos, mousePosition); //Debug.Log("<color=green>" + angle + "</color>"); TentacleAnimation ta = GetComponent <TentacleAnimation>(); float angleTest = angle / ta.rotations.Length; for (int i = 0; i <= ta.rotations.Length - 1; i++) { ta.rotations[i] = (int)(1.5 * angleTest); } // Debug.Log(string.Format("World: {0}, Angle {1}", mousePosition, angle)); }