Exemplo n.º 1
0
    private void Awake()
    {
        plankHolder        = transform.Find("Plank").gameObject;
        coalHolder         = transform.Find("Coal").gameObject;
        gunHolder          = transform.Find("Gun").gameObject;
        movementParticle   = transform.GetComponentInChildren <ParticleSystem>();
        throwChargesHolder = transform.Find("ThrowCharges");
        anim = GetComponent <Animator>();

        playerHolder = transform.Find("PlayerHolder").gameObject;

        pm            = GetComponent <PlayerMove>();
        ps            = GetComponent <PlayerShoot>();
        ps.enabled    = false;
        myPlayerThrow = GetComponent <ThrownObjectMove>();
    }
Exemplo n.º 2
0
    void Throw(int forceLevel)
    {
        AudioManager.SharedInstance.PlayClip(throwSounds[Random.Range(0, throwSounds.Length - 1)], 1f);
        anim.SetBool("pickup", false);
        anim.SetBool("throw", true);

        if (carryingPlank)
        {
            GameObject       plankGO = (GameObject)Instantiate(plankPrefab, plankHolder.transform.position, plankHolder.transform.rotation);
            ThrownObjectMove move    = plankGO.GetComponent <ThrownObjectMove>();
            move.setForceLevel(forceLevel);
            move.Move();
            Drop();
        }

        if (carryingCoal)
        {
            GameObject       coalGO = (GameObject)Instantiate(coalPrefab, plankHolder.transform.position, plankHolder.transform.rotation);
            ThrownObjectMove move   = coalGO.GetComponent <ThrownObjectMove>();
            move.setForceLevel(forceLevel);
            move.Move();
            Drop();
        }
        if (carryingGun)
        {
            GameObject gunGO = (GameObject)Instantiate(gunPrefab, plankHolder.transform.position, plankHolder.transform.rotation);
            gunGO.GetComponent <Gun>().SetAmmo(ps.ammo);
            ThrownObjectMove move = gunGO.GetComponent <ThrownObjectMove>();
            move.setForceLevel(forceLevel);
            move.Move();
            Drop();
        }
        if (carryingDynamite)
        {
            dynamiteGO.GetComponent <Rigidbody>().isKinematic = false;
            dynamiteGO.transform.parent = null;
            ThrownObjectMove move = dynamiteGO.GetComponent <ThrownObjectMove>();
            move.enabled = true;
            move.setForceLevel(forceLevel);
            move.Move();
            Drop();
        }

        if (carryingPlayer)
        {
            // undo all the stuff and unparent
            // only setactive scripts when grounded (do this in thrown objects move script)
            // Add force


            // !!! playerCarriedGO.GetComponent<PlayerMove>().enabled = false;
            // !!! playerCarriedGO.layer = 0;
            // !!! playerCarriedGO.GetComponentInChildren<ParticleSystem>().Stop();
            playerCarriedGO.GetComponent <Rigidbody>().isKinematic = false;
            playerCarriedGO.GetComponent <Collider>().enabled      = true;
            playerCarriedGO.transform.parent = null;

            ThrownObjectMove move = playerCarriedGO.GetComponent <ThrownObjectMove>();
            move.enabled = true;
            move.setForceLevel(forceLevel);
            move.Move();
            Drop();

            playerCarriedGO = null;
        }

        if (carryingPassenger)
        {
            passengerGO.GetComponent <Rigidbody>().isKinematic = false;
            passengerGO.transform.parent = null;
            ThrownObjectMove move = passengerGO.GetComponent <ThrownObjectMove>();
            move.enabled  = true;
            move.grounded = false;
            move.setForceLevel(forceLevel);
            move.Move();
            Drop();
        }
    }