コード例 #1
0
ファイル: NeedleController.cs プロジェクト: jslawski/ldjam44
    private IEnumerator MoveVertical(KeyCode pressedKey)
    {
        Vector3 originalPosition = this.transform.position;
        Vector3 cachedPosition   = this.transform.position;
        Vector3 finalPosition    = cachedPosition;

        bool synapseHit = false;

        while (Input.GetKey(pressedKey))
        {
            if (pressedKey == this.upKey)
            {
                finalPosition = new Vector3(originalPosition.x, originalPosition.y + this.maxUpDistance, originalPosition.z);
                if (synapseHit == false)
                {
                    NeedleController.onSynapseHit(this.upSynapse);
                    synapseHit = true;
                }
            }
            else if (pressedKey == this.downKey)
            {
                finalPosition = new Vector3(originalPosition.x, originalPosition.y - this.maxDownDistance, originalPosition.z);
                if (synapseHit == false)
                {
                    NeedleController.onSynapseHit(this.downSynapse);
                    synapseHit = true;
                }
            }

            cachedPosition          = Vector3.Lerp(cachedPosition, finalPosition, this.moveSpeed);
            this.transform.position = cachedPosition;
            yield return(null);
        }

        while (cachedPosition != originalPosition)
        {
            if (Vector3.Magnitude(cachedPosition - originalPosition) < 0.01f)
            {
                cachedPosition = originalPosition;
            }
            else
            {
                cachedPosition = Vector3.Lerp(cachedPosition, originalPosition, this.moveSpeed);
            }

            this.transform.position = cachedPosition;
        }

        this.moveCoroutine = null;
    }
コード例 #2
0
ファイル: NeedleController.cs プロジェクト: jslawski/ldjam44
    private IEnumerator MoveHorizontal(KeyCode pressedKey)
    {
        Transform originalTransform = this.transform;
        Transform cachedTransform   = this.transform;
        float     finalRotation     = (pressedKey == this.leftKey) ? this.maxRotation : 360 - this.maxRotation;
        float     thisRotationSpeed = (pressedKey == this.leftKey) ? this.rotationSpeed : -this.rotationSpeed;

        if (this.side == NeedleSide.Left && pressedKey == this.rightKey)
        {
            finalRotation += ((360f - finalRotation) / 2.5f);
        }
        else if (this.side == NeedleSide.Right && pressedKey == this.leftKey)
        {
            finalRotation = finalRotation - (finalRotation / 2.5f);
        }

        bool synapseHit = false;

        while (Input.GetKey(pressedKey))
        {
            if (cachedTransform.eulerAngles.z != finalRotation)
            {
                cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, cachedTransform.eulerAngles.z + thisRotationSpeed);

                if (pressedKey == this.leftKey && Mathf.Abs(cachedTransform.eulerAngles.z) > finalRotation)
                {
                    cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, finalRotation);
                    if (synapseHit == false)
                    {
                        NeedleController.onSynapseHit(this.leftSynapse);
                        synapseHit = true;
                    }
                }
                else if (pressedKey == this.rightKey && Mathf.Abs(cachedTransform.eulerAngles.z) < finalRotation)
                {
                    cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, finalRotation);
                    if (synapseHit == false)
                    {
                        NeedleController.onSynapseHit(this.rightSynapse);
                        synapseHit = true;
                    }
                }

                this.transform.rotation = cachedTransform.rotation;
            }

            yield return(null);
        }

        while (cachedTransform.eulerAngles.z != 0)
        {
            cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, cachedTransform.eulerAngles.z - thisRotationSpeed);

            if (pressedKey == this.leftKey && cachedTransform.eulerAngles.z > 300)
            {
                cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, 0);
            }
            else if (pressedKey == this.rightKey && cachedTransform.eulerAngles.z < finalRotation)
            {
                cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, 0);
            }

            this.transform.rotation = cachedTransform.rotation;
            yield return(null);
        }

        this.moveCoroutine = null;
    }