示例#1
0
 void Awake()
 {
     targetComponent = GetComponent <SCR_TongueTarget>();
     rb           = GetComponent <Rigidbody>();
     rend         = GetComponentInChildren <MeshRenderer>();
     defaultColor = rend.material.color;
 }
示例#2
0
    void Start()
    {
        targetComponent = GetComponent <SCR_TongueTarget>();
        varManager      = SCR_VarManager.Instance;

        // Check if this Gold Nut has been collected before
        foreach (var collIndex in varManager.CollectedGoldNuts)
        {
            if (collIndex == starIndex)
            {
                alreadyCollected = true;
            }
        }

        // Set correct mesh to visible
        if (alreadyCollected)
        {
            normalMesh.SetActive(false);
            collectedMesh.SetActive(true);
        }
        else
        {
            normalMesh.SetActive(true);
            collectedMesh.SetActive(false);
        }
    }
示例#3
0
    void Awake()
    {
        joint           = GetComponentInChildren <ConfigurableJoint>();
        targetComponent = GetComponent <SCR_TongueTarget>();

        randomAnimationOffset = Random.Range(-4, 4);
        defaultPosition       = transform.position;
    }
示例#4
0
    void Awake()
    {
        targetComponent = GetComponentInChildren <SCR_TongueTarget>();
        anim            = GetComponent <Animator>();

        targetComponent.transform.eulerAngles = Vector3.zero;
        activated = false;
    }
示例#5
0
    IEnumerator TongueEat(SCR_TongueTarget target)
    {
        // Stop targeting
        currentTarget = null;

        // Politely notify target that it's going to be eaten
        target.isBeingEaten = true;

        // Slow down time for a split second (experimental)
        Time.timeScale      = 0.5f;
        Time.fixedDeltaTime = Time.timeScale * 0.02f;
        float time = 0;

        while (time < 0.08f && target != null)
        {
            time += Time.deltaTime / Time.timeScale;
            tongueCollider.position = target.transform.position;
            yield return(null);
        }
        Time.timeScale      = 1;
        Time.fixedDeltaTime = Time.timeScale * 0.02f;

        if (target != null)
        {
            // Attach target to tongue
            target.transform.SetParent(tongueCollider);
            target.transform.localScale = target.transform.localScale * 0.75f;
        }

        // Start tongue retraction, wait until it finishes
        StartCoroutine(TongueRetract(tongueCollider.transform.position, 1));
        yield return(new WaitUntil(() => tongueState == TongueState.Retracted));

        // Give player reward if they should get it
        if (target != null && target.HasReward)
        {
            switch (target.rewardType)
            {
            case SCR_TongueTarget.RewardType.Coin:
                varManager.currentSeeds += target.rewardCount;
                // [Play coin sound]
                break;

            case SCR_TongueTarget.RewardType.TempReward2:
                // [Give player reward type]
                break;
            }

            // [Play animation]
        }

        // Destroy target
        if (target != null)
        {
            Destroy(target.gameObject);
        }
    }
示例#6
0
    void Awake()
    {
        targetComponent = GetComponent <SCR_TongueTarget>();


        randomAnimationOffset = Random.Range(-4, 4);
        currentPositionAnchor = transform.position;
        startingPosition      = transform.position;

        // make Move Destination relative to transform.position
        moveDestination += transform.position;
    }
    void FixedUpdate()
    {
        // Destroy self if player stops existing
        if (objectRefs.player == null)
        {
            Destroy(gameObject);
        }
        else
        {
            if (playerTongue == null)
            {
                playerTongue = objectRefs.player.GetComponent <SCR_Tongue>();
            }

            // Rotate icon to always face camera
            transform.LookAt(objectRefs.playerCamera.transform, objectRefs.playerCamera.transform.up);


            target = playerTongue.currentTarget;
            if (target != null)
            {
                Targeting();
            }
            else
            {
                NotTargeting();
            }

            // Rotate icon 45 degrees if locked on target
            Color lockSpriteColor;
            if (playerTongue.lockedOnTarget && target != null)
            {
                iconAngleOffset      = Mathf.Lerp(iconAngleOffset, -45, 0.6f);
                lockIcon.localScale  = Vector3.Lerp(lockIcon.localScale, Vector3.one, 0.6f);
                lockIconSprite.color = new Color(lockIconSprite.color.r, lockIconSprite.color.g, lockIconSprite.color.b, 1);
            }
            else
            {
                iconAngleOffset      = Mathf.Lerp(iconAngleOffset, 0, 0.6f);
                lockIcon.localScale  = Vector3.Lerp(lockIcon.localScale, new Vector3(1.5f, 1.5f, 1.5f), 0.6f);
                lockIconSprite.color = new Color(lockIconSprite.color.r, lockIconSprite.color.g, lockIconSprite.color.b, 0);
            }
            transform.localEulerAngles += new Vector3(0, 0, iconAngleOffset);
        }
    }
    public override void OnInspectorGUI()
    {
        SCR_TongueTarget tongueTarget = target as SCR_TongueTarget;

        tongueTarget.targetType = (SCR_TongueTarget.TargetType)EditorGUILayout.EnumPopup("Target Type", tongueTarget.targetType);

        switch (tongueTarget.targetType)
        {
        case SCR_TongueTarget.TargetType.Swing:
            tongueTarget.canSwingFromGround = EditorGUILayout.Toggle("Can Swing From Ground", tongueTarget.canSwingFromGround);
            tongueTarget.startWithVelocity  = EditorGUILayout.Toggle("Start With Velocity", tongueTarget.startWithVelocity);
            break;

        case SCR_TongueTarget.TargetType.Eat:
            tongueTarget.HasReward = EditorGUILayout.Toggle("Has Reward", tongueTarget.HasReward);
            if (tongueTarget.HasReward)
            {
                tongueTarget.rewardType = (SCR_TongueTarget.RewardType)EditorGUILayout.EnumPopup("Reward Type", tongueTarget.rewardType);

                tongueTarget.rewardCount = EditorGUILayout.IntField("Count", tongueTarget.rewardCount);
            }
            break;

        case SCR_TongueTarget.TargetType.Grab:
            tongueTarget.eventOnPull = EditorGUILayout.Toggle("Event On Pull", tongueTarget.eventOnPull);

            if (tongueTarget.eventOnPull)
            {
                tongueTarget.timeToPull = EditorGUILayout.FloatField("Time To Pull", tongueTarget.timeToPull);
            }

            break;

        case SCR_TongueTarget.TargetType.Deflect:

            break;

        default:
            break;
        }
        EditorGUILayout.Space();

        tongueTarget.targetIconOffset = EditorGUILayout.Vector3Field("Target Icon Offset", tongueTarget.targetIconOffset);
    }
示例#9
0
    /*
     * This region contains the targeting behavior used to determine which object Tongue Attack should target.
     *
     * FUNCTIONS IN THIS REGION:
     * Auto Target
     * Press Target
     * Initiate Lock-On
     * Unlock Targeting
     * Locked Target
     */

    void AutoTarget()
    {
        currentTarget = null;

        // Go through each target in scene. If it is within range & angle of player, and no other target is closer, set it as current target.
        foreach (var target in SCR_ObjectReferenceManager.Instance.tongueTargets)
        {
            float targetDistance = Vector3.Distance(tongueTargetAnchor.position, target.transform.position);
            bool  targetInRange  = targetDistance <= variables.maxTargetDistance;
            float angleToTarget  = Quaternion.Angle(tongueTargetAnchor.rotation, Quaternion.LookRotation((target.transform.position - tongueMeshAnchor.position).normalized, Vector3.up));

            if (targetInRange &&
                angleToTarget < variables.maxTargetAngle &&
                (currentTarget == null || targetDistance < Vector3.Distance(tongueTargetAnchor.position, currentTarget.transform.position)))
            {
                currentTarget = target;
            }
        }
    }
示例#10
0
    IEnumerator TongueGrab(SCR_TongueTarget target)
    {
        grabbedOnTarget = true;

        // Stop targeting
        currentTarget = null;
        ConfigurableJoint targetJoint = target.GetComponentInChildren <ConfigurableJoint>();

        // Temporarily turn player towards target to set up correct joint anchor position
        Quaternion playerStartingRotation = transform.rotation;
        Quaternion targetRotation         = Quaternion.LookRotation(new Vector3(target.transform.position.x, tongueTargetAnchor.position.y, target.transform.position.z) - tongueTargetAnchor.position);

        transform.rotation             = targetRotation;
        targetJoint.transform.rotation = targetRotation;

        // Connect player to target joint
        targetJoint.connectedBody = rb;

        // Set player's rotation back to where it was
        transform.rotation = playerStartingRotation;

        // get distance to grabbed object (this is used to determine if player is pulling on it)
        float maxTargetDistance = Vector3.Distance(tongueTargetAnchor.position, targetJoint.transform.position);

        // Disable normal movement
        movement.overrideRotation = true;
        movement.overrideJump     = true;

        float timeObjectPulled = 0;

        while (holdingTongueButton && !grabTerminated && movement.touchingGround && target != null)
        {
            // Turn player towards target
            targetRotation                 = Quaternion.LookRotation(new Vector3(target.transform.position.x, tongueTargetAnchor.position.y, target.transform.position.z) - tongueTargetAnchor.position);
            transform.rotation             = Quaternion.Slerp(transform.rotation, targetRotation, 20 * Time.deltaTime);
            targetJoint.transform.rotation = targetRotation;

            if (Vector3.Distance(tongueTargetAnchor.position, targetJoint.transform.position) <= maxTargetDistance + 0.2f)
            {
                // Behavior when not pulling on target (player is closer than when it was grabbed)

                // Allow free movement by updating joint's target distance
                targetJoint.targetPosition = new Vector3(0, 0, maxTargetDistance - Vector3.Distance(tongueTargetAnchor.position, targetJoint.transform.position));

                // Tell target that it isn't being pulled
                target.isBeingPulled = false;
                timeObjectPulled     = 0;
            }
            else
            {
                // Behavior when pulling on target (player is farther away than when it was grabbed)

                // restrict player from moving any farther away
                targetJoint.targetPosition = new Vector3(0, 0, 0);

                target.isBeingPulled = true;

                // If pulling should trigger an event on target, trigger it
                timeObjectPulled += Time.deltaTime;
                if (timeObjectPulled >= target.timeToPull && target.eventOnPull)
                {
                    target.eventTriggered = true;
                }
            }

            tongueCollider.position = target.transform.position;

            yield return(null);
        }

        if (target != null)
        {
            // Break connection to joint
            targetJoint.connectedBody = null;
            target.isBeingPulled      = false;
        }

        grabbedOnTarget = false;

        // Start retracting tongue
        StartCoroutine(TongueRetract(tongueCollider.transform.position, 1));

        // If player was forced to release grab:
        if (grabTerminated)
        {
            // Jerk player backwards
            rb.AddRelativeForce(0, 0, -6, ForceMode.Impulse);
            movement.overrideNormalMovement = true;

            // Delay enabling normal movement
            yield return(new WaitForSeconds(0.5f));
        }

        // Enable normal movement
        movement.overrideJump           = false;
        movement.overrideRotation       = false;
        movement.overrideNormalMovement = false;

        grabTerminated = false;
    }
示例#11
0
    /*
     * This region contains the various interactions that can be performed once tongue has hit a target.
     * The type of interaction performed is determined by checking the targetType of the target object.
     *
     * FUNCTIONS IN THIS REGION:
     * Tongue Swing
     * Tongue Eat
     * Tongue Grab
     * Terminate Grab
     */

    IEnumerator TongueSwing(SCR_TongueTarget target)
    {
        // Stop targeting
        currentTarget = null;
        tongueState   = TongueState.Attached;

        ConfigurableJoint targetJoint   = target.GetComponentInChildren <ConfigurableJoint>();
        Rigidbody         targetJointRb = targetJoint.GetComponent <Rigidbody>();

        // Turn player towards target
        Quaternion targetRotation = Quaternion.LookRotation(target.transform.position - tongueTargetAnchor.position);

        transform.rotation             = targetRotation;
        targetJoint.transform.rotation = targetRotation;

        // Tell target that player is swinging on it
        target.isBeingSwung = true;

        // Connect player to target joint
        targetJoint.connectedBody = rb;

        // Set target distance while swinging (promote to variable later)
        targetJoint.targetPosition = new Vector3(0, 0, Vector3.Distance(tongueTargetAnchor.position, targetJoint.transform.position) - variables.swingDistance);

        // Set initial swing velocity. Change this in future to convert linear velocity to angular
        //rb.velocity = rb.velocity.normalized * 7;
        rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);

        // Deactivate normal movement
        movement.overrideNormalMovement = true;
        movement.overrideJump           = true;
        movement.overrideRotation       = true;
        movement.canMidairJump          = false;
        rb.constraints &= ~RigidbodyConstraints.FreezeRotationX;
        rb.constraints &= ~RigidbodyConstraints.FreezeRotationY;
        rb.constraints &= ~RigidbodyConstraints.FreezeRotationZ;

        float swingTime = 0;

        while ((holdingTongueButton || swingTime < 0.2f) && target != null)
        {
            swingTime += Time.deltaTime;

            // Add some forward rotation at the beginning of swing
            if (target.startWithVelocity && swingTime < 0.1f)
            {
                targetJointRb.AddRelativeTorque(-400 * Time.deltaTime, 0, 0, ForceMode.Impulse);
            }

            tongueCollider.position = target.transform.position;
            yield return(null);
        }

        if (target != null)
        {
            // Break connection to joint
            targetJoint.connectedBody = null;

            // Tell target that player stopped swinging on it
            target.isBeingSwung = false;
        }


        // Set velocity on swing end. Change this in future to convert linear velocity to angular
        //rb.velocity = rb.velocity.normalized * targetJointRb.angularVelocity.magnitude * 2;
        movement.externalVelocity.velocity = rb.velocity;
        if (movement.externalVelocity.velocity.y < 1)
        {
            movement.externalVelocity.velocity = new Vector3(movement.externalVelocity.velocity.x, 1, movement.externalVelocity.velocity.z);
        }

        // Re-activate normal movement
        movement.overrideNormalMovement = false;
        movement.overrideJump           = false;
        movement.overrideRotation       = false;
        rb.constraints = RigidbodyConstraints.FreezeRotation;

        // Refresh midair jump after swinging
        movement.canMidairJump = true;

        StartCoroutine(TongueRetract(tongueCollider.transform.position, 1));
    }
示例#12
0
    /*
     * This region contains the Tongue Attack and Retract that constitute the beginning and end of every tongue interaction.
     *
     * FUNCTIONS IN THIS REGION:
     * Tongue Attack
     * Tongue Retract
     */


    IEnumerator TongueAttack(SCR_TongueTarget target)
    {
        // Tell target it's being attacked
        target.isBeingAttacked = true;

        // Tell animation that tongue is being extended
        animScript.tongueOut = true;

        float TongueDistance = 0;

        while (TongueDistance < 1 && target != null)
        {
            // Linearly interpolate tongue's position from body to target
            // (promote speed to variable later)
            TongueDistance         += 10 * Time.deltaTime;
            tongueCollider.position = Vector3.Lerp(tongueMeshAnchor.position, target.transform.position, variables.tongueAttackCurve.Evaluate(TongueDistance));

            yield return(null);
        }

        // Tell target attack is finished
        target.isBeingAttacked = false;

        // Check what type of tongue interaction should be used
        switch (target.targetType)
        {
        case SCR_TongueTarget.TargetType.Swing:
            if (!movement.touchingGround || target.canSwingFromGround)
            {
                StartCoroutine(TongueSwing(target));
            }
            else
            {
                StartCoroutine(TongueRetract(target.transform.position, 1));
            }
            break;

        case SCR_TongueTarget.TargetType.Eat:
            StartCoroutine(TongueEat(target));
            break;

        case SCR_TongueTarget.TargetType.Grab:
            if (movement.touchingGround)
            {
                StartCoroutine(TongueGrab(target));
            }
            else
            {
                StartCoroutine(TongueRetract(target.transform.position, 1));
            }
            break;

        case SCR_TongueTarget.TargetType.Deflect:
            // Maybe update this later to add effect
            StartCoroutine(TongueRetract(target.transform.position, 1));
            break;

        default:
            StartCoroutine(TongueRetract(tongueCollider.position, 1));
            break;
        }
    }
示例#13
0
 void Awake()
 {
     targetComponent = GetComponent <SCR_TongueTarget>();
 }
示例#14
0
 void Start()
 {
     targetComponent = GetComponent <SCR_TongueTarget>();
     varManager      = SCR_VarManager.Instance;
 }