IEnumerator RunToTargetPositon(float targetPosX) { arrived = false; StartCoroutine(OpenTools()); Debug.Log("============start=============="); float curTime = 0; Vector3 startPos = this.transform.position; carState = (targetPosX - this.transform.position.x) > 0?CarState.runForward:CarState.runBack; while (Mathf.Abs(targetPosX - this.transform.position.x) > 0.001f) { yield return(null); curTime += Time.deltaTime; this.transform.position = new Vector3(Mathf.Lerp(startPos.x, targetPosX, curTime), this.transform.position.y, this.transform.position.z); } carState = CarState.stop; ropeState = RopeState.Elong; yield return(StartCoroutine(OperateTheRope())); while (!arrived) { yield return(null); } }
public IEnumerator OperateTheRope() { float countHeight = 0; int relative = 0; while (ropeState != RopeState.Stop) { relative = (int)ropeState; yield return(null); countHeight += 100 * Time.deltaTime; if (countHeight > 1) { rope.height = rope.height + 8 * relative; toolHead.transform.localPosition += new Vector3(0, -8 * relative, 0); ropeRotate.transform.Rotate(new Vector3(0, 0, -5 * relative)); countHeight = 0; if (toolHead.transform.localPosition.y > -60)//收缩回来停止 { ropeState = RopeState.Stop; arrived = true; } } } }
void Update() { if (Input.GetMouseButtonDown(1)) { ropeState = RopeState.Fly; isRopeBreaked = false; Shot(); } if (Input.GetMouseButtonUp(1)) { DestroySpring(); ropeRenderer.Hide(); } if (Input.GetMouseButton(1) && !isRopeBreaked) { ropeRenderer.Draw(pointer.position, hook.transform.position, ropeLength); } else { hook.transform.position = pointer.position; hook.rigidbody.velocity = Vector3.zero; } }
public void DestroySpring() { ropeState = RopeState.Disabled; hook.DestroyJoint(); if (_springJoint) { Destroy(_springJoint); } _springJoint = null; }
public IEnumerator CloseTools() { ropeState = RopeState.Stop; while (support[0].transform.localEulerAngles.z > 1) { yield return(null); support[0].transform.localEulerAngles += new Vector3(0, 0, 50 * Time.deltaTime); support[1].transform.localEulerAngles += new Vector3(0, 0, -50 * Time.deltaTime); } ropeState = RopeState.Eshort; StartCoroutine(OperateTheRope()); }
public void CreateSpring() { ropeState = RopeState.Active; if (_springJoint is null) { _springJoint = gameObject.AddComponent <SpringJoint>(); _springJoint.connectedBody = hook.rigidbody; _springJoint.anchor = pointer.localPosition; _springJoint.autoConfigureConnectedAnchor = false; _springJoint.connectedAnchor = Vector3.zero; ropeLength = Vector3.Distance(pointer.position, hook.transform.position); _springJoint.maxDistance = ropeLength; _springJoint.spring = 200; _springJoint.damper = 10; } }
public void Shoot(Vector2 direction) { if (!ValidateDirection(direction)) { return; } ropeSaved = false; Clear(); // para evitar bugs hit = Physics2D.Raycast(shootPoint.position, direction, ropeLength, wallsMask); var hitSomethingToHookOnto = hit.collider != null && hit.rigidbody != null && Vector2.Distance(hit.point, transform.position) > minDistance; if (hitSomethingToHookOnto) { SetConnection(); endRope = shootPoint.position; State = RopeState.Shooting; } else { State = RopeState.Disconnected; } }
public void GetPrize() { ropeState = RopeState.Stop; }
public void SetRopeState(RopeState p_state) { m_prevRopeState = m_ropeState; m_ropeState = p_state; ropeStateModified = true; }
void OnConnectRope() { SetConnection(); State = RopeState.Hang; }
void Clear() { State = RopeState.Disconnected; }