void release() { springjoint.enabled = false; justhooked = false; justaddedforce = false; ishooked = false; justunhooked = true; hookanchor.isnothookedtothis(); foreach (GameObject hook in hooks) { hookanchor = hook.GetComponent <HookAnchor>(); hookanchor.isnothookedtothis(); hookanchor.isnotclosetothis(); } if (LastClosestHook != null) { lasthookanchor.isnothookedtothis(); } }
void distancecheck() { // if (!ishooked) // { Vector3 position = transform.position; foreach (GameObject hook in hooks) { Vector3 diff = hook.transform.position - position; float curdistance = diff.sqrMagnitude; if (curdistance < distance) { if (hook != ClosestHook && ClosestHook != null) { LastClosestHook = ClosestHook; lasthookanchor = LastClosestHook.GetComponent <HookAnchor>(); lasthookanchor.isnotclosetothis(); } distance = curdistance; ClosestHook = hook; hookanchor = hook.GetComponent <HookAnchor>(); hookanchor.isclosetothis(); if (!ishooked) { currenthook = hook; currenthookpoeition = currenthook.transform.position; rb2d = currenthook.GetComponent <Rigidbody2D>(); } } } // } // else // { // } }
void Update() { distance = Mathf.Infinity; distancecheck(); spritechanging(); colliderchanging(); linerendrercall(); if (transform.position.y <= -killzone && !win.wonlevl) { foreach (GameObject hook in hooks) { hookanchor = hook.GetComponent <HookAnchor>(); hookanchor.isnothookedtothis(); hookanchor.isnotclosetothis(); } gm.respawn(); Destroy(gameObject); } else if (!win.wonlevl) { #if UNITY_EDITOR if (Input.GetMouseButtonDown(0) || Input.GetButtonDown("Jump")) { attach(); } if (Input.GetMouseButtonUp(0) || Input.GetButtonUp("Jump")) { release(); vel = rb.velocity; } // #elif UNITY_ANDROID // if (Input.touchCount > 0 ) // { // Touch touch = Input.GetTouch(0); // if (touch.phase == TouchPhase.Began && touch.position.y < Screen.height/2) // { // attach(); // } // if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) // { // release(); // } // } #endif } else if (win.wonlevl) { if (!justspawned) { spawnparticles(); Vector2 diff = rb.velocity; diff.Normalize(); float rotz = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotz - 90); } } }
void FixedUpdate() { if (rb.velocity.magnitude > max) { foreach (GameObject hook in hooks) { hookanchor = hook.GetComponent <HookAnchor>(); hookanchor.isnothookedtothis(); hookanchor.isnotclosetothis(); } gm.respawn(); Destroy(gameObject); } else if (win.wonlevl) { rb.gravityScale = 0; rb.velocity = Vector2.Lerp(rb.velocity, Vector2.zero, 0.1f * Time.deltaTime); } else if (ishooked && !justaddedforce && rb.velocity.magnitude < 15 && justhooked) { justaddedforce = true; //rb.velocity = rb.velocity * 1.3f; rb.velocity = Vector2.Lerp(rb.velocity, rb.velocity * 1.3f, 0.1f * Time.deltaTime); #region // if (transform.position.x < ClosestHook.transform.position.x && transform.position.y < ClosestHook.transform.position.y)//set back sprite for the character // { // rb.velocity = rb.velocity * push; // //rb.AddForce(forc); // justhooked = false; // } // else if (transform.position.x > ClosestHook.transform.position.x && transform.position.y < ClosestHook.transform.position.y)//set front sprite for the character // { // rb.velocity = rb.velocity * push; // //rb.velocity = Vector2.zero; // //rb.AddForce(-forc); // justhooked = false; // } // else if (transform.position.y > ClosestHook.transform.position.y) // { // rb.velocity = rb.velocity * push; // //rb.velocity = Vector2.zero; // //rb.AddForce(-downfrc); // justhooked = false; // } #endregion } else if (justunhooked) { justunhooked = false; rb.velocity = vel; } }