Beispiel #1
0
    private IEnumerator ApplyForceToSection(TubeSection section, Vector3 force, float duration)
    {
        var elapsed = 0f;

        while (elapsed < duration)
        {
            section.rigidbody.AddForce(force, ForceMode.Force);
            elapsed += Time.deltaTime;
            yield return(null);
        }
    }
Beispiel #2
0
    private void CreateTubeMan()
    {
        var         startPos            = transform.position;
        TubeSection previousTubeSection = null;

        _torsoSections = new TubeSection[numberTorsoSections];
        for (int i = 0; i < numberTorsoSections; i++)
        {
            var pos = startPos + Vector3.up * i * tubeSectionPrefab.transform.localScale.y;
            pos += Vector3.forward * UnityEngine.Random.Range(-0.1f, 0.1f);
            pos += Vector3.right * UnityEngine.Random.Range(-0.1f, 0.1f);
            var tubeSection = Instantiate(tubeSectionPrefab, pos, Quaternion.identity);
            tubeSection.playerIndex    = playerIndex;
            tubeSection.maxHealthColor = color;
            if (i == faceIndex)
            {
                var face = Instantiate(facePrefab, Vector3.zero, Quaternion.identity);
                face.transform.parent        = tubeSection.transform;
                face.transform.localPosition = transform.forward * 0.5f;
            }
            if (i == heartIndex)
            {
                var heart = Instantiate(heartPrefab, Vector3.zero, Quaternion.identity);
                heart.transform.parent        = tubeSection.transform;
                heart.transform.localPosition = transform.forward * 0.5f;
            }
            if (previousTubeSection != null)
            {
                tubeSection.joint.connectedBody = previousTubeSection.rigidbody;
            }
            else
            {
                ConfigureRootJoint(tubeSection.joint);
                tubeSection.joint.connectedAnchor = startPos;
            }
            SetJointLimits(tubeSection.joint, torsoAngle);
            _torsoSections[i]   = tubeSection;
            previousTubeSection = tubeSection;
            if (i >= numberTorsoSections - 1)
            {
                tubeSection.gameObject.layer = 8;
                tubeSection.isDamager        = true;
            }
        }
        TubeSection previousRightArmSection = null;
        TubeSection previousLeftArmSection  = null;

        _rightArmSections = new TubeSection[numberTorsoSections];
        _leftArmSections  = new TubeSection[numberTorsoSections];
        for (int i = 0; i < numberArmSections; i++)
        {
            var torsoSection    = _torsoSections[armTorsoNode];
            var rightArmPos     = torsoSection.transform.position + Vector3.right * (i + 1) * rightArmSectionPrefab.transform.localScale.x;
            var leftArmPos      = torsoSection.transform.position + Vector3.left * (i + 1) * leftArmSectionPrefab.transform.localScale.x;
            var rightArmSection = Instantiate(rightArmSectionPrefab, rightArmPos, Quaternion.AngleAxis(90f, Vector3.forward));
            rightArmSection.playerIndex    = playerIndex;
            rightArmSection.maxHealthColor = color;
            var leftArmSection = Instantiate(leftArmSectionPrefab, leftArmPos, Quaternion.AngleAxis(90f, Vector3.forward));
            leftArmSection.playerIndex    = playerIndex;
            leftArmSection.maxHealthColor = color;
            if (previousRightArmSection != null)
            {
                rightArmSection.joint.connectedBody = previousRightArmSection.rigidbody;
                leftArmSection.joint.connectedBody  = previousLeftArmSection.rigidbody;
            }
            else
            {
                rightArmSection.joint.connectedBody   = torsoSection.rigidbody;
                rightArmSection.joint.connectedAnchor = new Vector3(0.5f, 0f, 0f);
                leftArmSection.joint.connectedBody    = torsoSection.rigidbody;
                leftArmSection.joint.connectedAnchor  = new Vector3(-0.5f, 0f, 0f);
            }
            _rightArmSections[i] = rightArmSection;
            _leftArmSections[i]  = leftArmSection;
            SetJointLimits(rightArmSection.joint, armAngle);
            SetJointLimits(leftArmSection.joint, armAngle);
            previousRightArmSection = rightArmSection;
            previousLeftArmSection  = leftArmSection;
            if (i >= numberArmSections - 2)
            {
                rightArmSection.gameObject.layer = 8;
                rightArmSection.isDamager        = true;
                leftArmSection.gameObject.layer  = 8;
                leftArmSection.isDamager         = true;
            }
        }
    }