Exemple #1
0
    void PickupTorch(GameObject Player)
    {
        if (Input.GetKey(KeyCode.X))
        {
            //Set the parent of the torch to the player
            transform.SetParent(Player.transform);

            //Reset local positions and euler angles
            transform.GetChild(0).localPosition = new Vector3(1.2f, 2f, 0f);
            transform.localPosition             = new Vector3(-1f, 0f, 0f);
            transform.localEulerAngles          = new Vector3(0f, 0f, 60f);

            //Obtain the animator from the player
            Animator PlayerAnimations = Player.GetComponent <Animator>();

            //Override the animator controller
            PlayerAnimations.runtimeAnimatorController = TorchAnimationOverride;

            //Obtain the torch script to set this gameobject as the torch
            TL_Torch TorchScript = Player.GetComponent <TL_Torch>();
            TorchScript.Torch = gameObject;
            TL_CharacterHealth HealthScript = Player.GetComponent <TL_CharacterHealth>();
            HealthScript.Torch = gameObject;

            //Destroy the box collider and this script
            Destroy(GetComponent <BoxCollider2D>());
            Destroy(this);
        }
    }
    void Start()
    {
        //Find the player
        PlayerCharacter = GameObject.FindGameObjectWithTag("Player");

        //Obtain the audio source
        CampfireAudio = GetComponent <AudioSource>();

        //Obtain the respawn script and the character health script from the player character
        RespawnScript = PlayerCharacter.GetComponent <TL_Respawn>();
        HealthScript  = PlayerCharacter.GetComponent <TL_CharacterHealth>();

        //Ignore the collisoin between the player character and this checkpoint
        Physics2D.IgnoreCollision(PlayerCharacter.GetComponent <BoxCollider2D>(), transform.GetComponent <BoxCollider2D>());
    }