Пример #1
0
    public void DetachArm()
    {
        attached   = false;
        attachable = false;

        body.attachedArms.Remove(this);
        // make lose of body
        //attachmentPoint.attachedArm = null;
        //attachmentPoint.attachable = true;
        attachmentPoint    = null;
        fixedJoint.enabled = false;

        // Put arm back on default layer
        Transform[] _children = GetComponentsInChildren <Transform>();
        foreach (Transform child in _children)
        {
            child.gameObject.layer = 0;
        }

        // start attach cooldown to prevent instant re attachment.
        StartCoroutine(DetachCooldown());

        // play sound
        string randomRipSound = "Rip_" + Random.Range(1, 3).ToString();

        AudioManager.instance.Play(randomRipSound);
        AudioManager.instance.ChangePitch(randomRipSound, Random.Range(0.7f, 1.3f));

        Debug.Log("Arm detached");
    }
Пример #2
0
    public void DetachHead()
    {
        attached   = false;
        attachable = false;

        attachmentPointJoint.enabled = false;

        attachmentPoint = null;

        if (attachmentPointJoint.connectedBody != null)
        {
            attachmentPointJoint.connectedBody = null;
        }

        Transform[] _children = GetComponentsInChildren <Transform>();
        foreach (Transform child in _children)
        {
            child.gameObject.layer = 9;
        }

        string randomRipSound = "Rip_" + Random.Range(1, 3).ToString();

        AudioManager.instance.Play(randomRipSound);
        AudioManager.instance.ChangePitch(randomRipSound, Random.Range(0.7f, 1.3f));
    }
Пример #3
0
    public void AttachHead(BodyJointBehaviour bodyPoint)
    {
        gm.EndGame();
        if (attachable && !attached)
        {
            attached   = true;
            attachable = false;

            attachmentPoint = bodyPoint;

            //attachmentPointJoint fix
            transform.position = new Vector3(attachmentPoint.transform.position.x - 0.5f * transform.up.x, attachmentPoint.transform.position.y - 0.5f * transform.up.y, attachmentPoint.transform.position.z);

            attachmentPointJoint.connectedBody   = body.GetComponent <Rigidbody2D>();
            attachmentPointJoint.connectedAnchor = new Vector2(body.transform.InverseTransformPoint(attachmentPoint.transform.position).x, body.transform.InverseTransformPoint(attachmentPoint.transform.position).y);
            transform.position           = new Vector3(attachmentPoint.transform.position.x - 0.5f * transform.up.x, attachmentPoint.transform.position.y - 0.5f * transform.up.y, attachmentPoint.transform.position.z);
            attachmentPointJoint.enabled = true;

            Transform[] _children = GetComponentsInChildren <Transform>();
            foreach (Transform child in _children)
            {
                child.gameObject.layer = 8;
            }

            // play sound
            if (selected)
            {
                string randomAttachSound = "Attach_" + Random.Range(1, 4).ToString();
                AudioManager.instance.Play(randomAttachSound);
                AudioManager.instance.ChangePitch(randomAttachSound, Random.Range(0.7f, 1.3f));
            }
        }
    }
Пример #4
0
    public void AttachLeg(BodyJointBehaviour bodyPoint)
    {
        if (attachable && !attached)
        {
            leg.AttachLeg(bodyPoint);
            attached   = true;
            attachable = false;

            body.attachedLegs.Add(this);
            attachmentPoint   = bodyPoint;
            attachmentPointRb = attachmentPoint.GetComponent <Rigidbody2D>();
            //attachmentPointJoint = GetComponent<SpringJoint2D>();
            //attachmentPointJoint = attachmentPoint.GetComponent<SpringJoint2D>();

            attachmentPointJoint.autoConfigureDistance = false;
            //attachmentPointJoint.connectedAnchor = new Vector2 (body.transform.InverseTransformPoint(bodyPoint.transform.position).x, body.transform.InverseTransformPoint(bodyPoint.transform.position).y);
            //attachmentPointJoint.autoConfigureConnectedAnchor = true;
            attachmentPointJoint.distance  = springDistance;
            attachmentPointJoint.frequency = springFreq;

            attachCooldown = true;
            StartCoroutine(AttachCooldown());
            //attachmentPointJoint.autoConfigureDistance = false;
            //attachmentPointJoint.distance = springDistance;
            //attachmentPointJoint.frequency = springFreq*6;

            //transform.position = attachmentPoint.transform.position;
            //hingeJoint.enabled = true;
            //hingeJoint.connectedBody = body.GetComponent<Rigidbody2D>();
            // Move layers to avoid nasty collisions
            Transform[] _children = GetComponentsInChildren <Transform>();
            foreach (Transform child in _children)
            {
                child.gameObject.layer = 8;
            }

            // play sound
            if (selected)
            {
                string randomAttachSound = "Attach_" + Random.Range(1, 4).ToString();
                AudioManager.instance.Play(randomAttachSound);
                AudioManager.instance.ChangePitch(randomAttachSound, Random.Range(0.7f, 1.3f));
            }

            // if first limb to attach, cue the music
            if (!GameManager.Instance.hasAttachedFirstLimb && selected)
            {
                GameManager.Instance.AttachedFirstLimb();
            }

            Debug.Log("Foot Attached");
        }
    }
Пример #5
0
    public void AttachLeg(BodyJointBehaviour bodyPoint)
    {
        attachmentPoint = bodyPoint;
        //attachmentPointJoint = attachmentPoint.GetComponent<SpringJoint2D>();

        transform.position = new Vector3(attachmentPoint.transform.position.x - 0.5f * transform.up.x, attachmentPoint.transform.position.y - 0.5f * transform.up.y, attachmentPoint.transform.position.z);

        hingeJointLeg.connectedBody   = body.GetComponent <Rigidbody2D>();
        hingeJointLeg.connectedAnchor = new Vector2(body.transform.InverseTransformPoint(attachmentPoint.transform.position).x, body.transform.InverseTransformPoint(attachmentPoint.transform.position).y);
        transform.position            = new Vector3(attachmentPoint.transform.position.x - 0.5f * transform.up.x, attachmentPoint.transform.position.y - 0.5f * transform.up.y, attachmentPoint.transform.position.z);
        hingeJointLeg.enabled         = true;

        Transform[] _children = GetComponentsInChildren <Transform>();
        foreach (Transform child in _children)
        {
            child.gameObject.layer = 8;
        }
    }
Пример #6
0
    public void DetachArm()
    {
        attached   = false;
        attachable = false;

        attachmentPoint      = null;
        attachmentPointJoint = null;

        fixedJoint.enabled = false;
        // Put arm back on default layer
        Transform[] _children = GetComponentsInChildren <Transform>();
        foreach (Transform child in _children)
        {
            child.gameObject.layer = 0;
        }
        // start attach cooldown to prevent instant re attachment.
        StartCoroutine(DetachCooldown());

        Debug.Log("Arm detached");
    }
Пример #7
0
    public void AttachArm(BodyJointBehaviour bodyPoint)
    {
        if (attachable && !attached)
        {
            attached   = true;
            attachable = false;

            // Stick to body
            body.attachedArms.Add(this);
            attachmentPoint          = bodyPoint;
            transform.position       = attachmentPoint.transform.position;
            fixedJoint.enabled       = true;
            fixedJoint.connectedBody = body.GetComponent <Rigidbody2D>();

            attachCooldown = true;
            StartCoroutine(AttachCooldown());

            // Move layers to avoid nasty collisions
            Transform[] _children = GetComponentsInChildren <Transform>();
            foreach (Transform child in _children)
            {
                child.gameObject.layer = 8;
            }

            // if first limb to attach, cue the music
            if (!GameManager.Instance.hasAttachedFirstLimb && selected)
            {
                GameManager.Instance.AttachedFirstLimb();
            }

            // play sound
            if (selected)
            {
                string randomAttachSound = "Attach_" + Random.Range(1, 4).ToString();
                AudioManager.instance.Play(randomAttachSound);
                AudioManager.instance.ChangePitch(randomAttachSound, Random.Range(0.7f, 1.3f));
            }

            Debug.Log("Arm attached");
        }
    }
Пример #8
0
    public void DetachFoot()
    {
        leg.DetachLeg();

        attached   = false;
        attachable = false;

        body.attachedLegs.Remove(this);
        attachmentPointJoint.enabled = false;

        //attachmentPointJoint.autoConfigureDistance = true;
        //attachmentPointJoint.frequency = 1;

        attachmentPoint = null;
        if (attachmentPointJoint.connectedBody != null)
        {
            attachmentPointJoint.connectedBody = null;
        }
        //attachmentPointJoint = null;

        //fixedJoint.enabled = false;
        // Put arm back on default layer
        Transform[] _children = GetComponentsInChildren <Transform>();
        foreach (Transform child in _children)
        {
            child.gameObject.layer = 9;
        }
        // start attach cooldown to prevent instant re attachment.
        StartCoroutine(DetachCooldown());

        // play sound
        string randomRipSound = "Rip_" + Random.Range(1, 3).ToString();

        AudioManager.instance.Play(randomRipSound);
        AudioManager.instance.ChangePitch(randomRipSound, Random.Range(0.7f, 1.3f));

        Debug.Log("Foot detached");
    }
Пример #9
0
    public void AttachArm(BodyJointBehaviour bodyPoint)
    {
        if (attachable && !attached)
        {
            attached   = true;
            attachable = false;

            attachmentPoint      = bodyPoint;
            attachmentPointJoint = attachmentPoint.GetComponent <SpringJoint2D>();

            transform.position       = attachmentPoint.transform.position;
            fixedJoint.enabled       = true;
            fixedJoint.connectedBody = body.GetComponent <Rigidbody2D>();
            // Move layers to avoid nasty collisions
            Transform[] _children = GetComponentsInChildren <Transform>();
            foreach (Transform child in _children)
            {
                child.gameObject.layer = 8;
            }

            Debug.Log("Arm attached");
        }
    }
Пример #10
0
 // Start is called before the first frame update
 void Start()
 {
     attachmentPointChild = GetComponentInChildren <BodyJointBehaviour>();
 }