コード例 #1
0
    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);
        }
    }
コード例 #2
0
    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;
                }
            }
        }
    }
コード例 #3
0
    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;
        }
    }
コード例 #4
0
 public void DestroySpring()
 {
     ropeState = RopeState.Disabled;
     hook.DestroyJoint();
     if (_springJoint)
     {
         Destroy(_springJoint);
     }
     _springJoint = null;
 }
コード例 #5
0
    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());
    }
コード例 #6
0
 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;
     }
 }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
 public void GetPrize()
 {
     ropeState = RopeState.Stop;
 }
コード例 #9
0
ファイル: scr_PSM.cs プロジェクト: MrPompon/Tale-Revived
 public void SetRopeState(RopeState p_state)
 {
     m_prevRopeState   = m_ropeState;
     m_ropeState       = p_state;
     ropeStateModified = true;
 }
コード例 #10
0
 void OnConnectRope()
 {
     SetConnection();
     State = RopeState.Hang;
 }
コード例 #11
0
 void Clear()
 {
     State = RopeState.Disconnected;
 }