Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // Os códigos aqui cuida pra que a Ash se conecte a alguma coisa

        // Só pra garantir que ainda não tem nenhum Joint nem RigidBody...
        if (jointado && rb == null && dj3D == null)
        {
            Debug.Log("deu if");

            // Ativa a animação de gancho
            anim.SetBool("Enganchado", true);

            // Tira o controle de player
            ashCtrl.sobControle = false;
            // Desliga o character controller
            cc.enabled = false;
            // Adiciona o DistanceJoint3D
            rb   = gameObject.AddComponent <Rigidbody>();
            dj3D = gameObject.AddComponent <DistanceJoint3D>();
            // Conecta o Hinjejoint ao Rigidbody identificado
            dj3D.penduradoEm = conectadoEm.transform;
        }
        else if (!jointado && rb != null && dj3D != null)
        {
            // Destrói os dois componentes
            Destroy(dj3D);
            Destroy(rb);

            // Reativa o Character Controller
            cc.enabled = true;
        }

        if (!ganchoAtivo && ganchoAtual == null && Input.GetButtonDown("FaceY"))
        {
            // Ativa o som do gancho
            FMODUnity.RuntimeManager.PlayOneShot("event:/sfx/launching_hook");

            anim.SetTrigger("LancaGancho");
            ganchoAtual = Instantiate(ganchoPrefab, mao.position, rotacao, mao);
            ganchoAtivo = true;
        }
        else if (ganchoAtivo && ganchoAtual != null && Input.GetButtonDown("FaceA"))
        {
            Abortar();
        }
    }
Ejemplo n.º 2
0
    private void AddChildren(Transform parent)
    {
        for (int i = 0; i < parent.childCount; i++)
        {
            child          = parent.GetChild(i);
            representative = new GameObject(child.gameObject.name);

            representative.transform.parent = RigidBodyContainer.transform;

            //rigidbody
            childRigidBody                = representative.gameObject.AddComponent <Rigidbody>();
            childRigidBody.useGravity     = true;
            childRigidBody.isKinematic    = false;
            childRigidBody.freezeRotation = true;
            childRigidBody.mass           = RigidbodyMass;

            //collider
            sphereCollider        = representative.gameObject.AddComponent <SphereCollider>();
            sphereCollider.center = Vector3.zero;
            sphereCollider.radius = ColliderRadius;

            //DistanceJoint
            joint = representative.gameObject.AddComponent <DistanceJoint3D>();
            joint.ConnectedRigidbody       = parent;
            joint.DetermineDistanceOnStart = true;
            joint.Spring = JointSpring;
            joint.Damper = JointDamper;
            joint.DetermineDistanceOnStart = false;
            joint.Distance = Vector3.Distance(parent.position, child.position);

            //add copy source
            CopySource.Add(representative.transform);
            CopyDestination.Add(child);

            AddChildren(child);
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        // Os códigos aqui cuida pra que a Ash se conecte a alguma coisa

        // Só pra garantir que ainda não tem nenhum Joint nem RigidBody...
        if (jointado && rb == null && dj3D == null)
        {
            anim.SetBool("Enganchado", true);
            // Desliga o character controller
            cc.enabled = false;
            // Adiciona o DistanceJoint3D
            rb   = gameObject.AddComponent <Rigidbody>();
            dj3D = gameObject.AddComponent <DistanceJoint3D>();
            // Conecta o Hinjejoint ao Rigidbody identificado
            dj3D.penduradoEm = conectadoEm.transform;
        }
        else if (!jointado && rb != null && dj3D != null)
        {
            // Destrói os dois componentes
            Destroy(dj3D);
            Destroy(rb);

            // Reativa o Character Controller
            cc.enabled = true;
        }

        if (!ganchoAtivo && ganchoAtual == null && Input.GetButtonDown("RightTrigger"))
        {
            anim.SetTrigger("LancaGancho");
            ganchoAtual = Instantiate(ganchoPrefab, mao.position, rotacao, mao);
            ganchoAtivo = true;
        }
        else if (ganchoAtivo && ganchoAtual != null && Input.GetButtonDown("FaceA"))
        {
            Abortar();
        }
    }