Quest Rewards

Announcements, support questions, and discussion for Quest Machine.
Post Reply
tootyboi95
Posts: 16
Joined: Wed Sep 29, 2021 1:51 pm

Quest Rewards

Post by tootyboi95 »

Hi Tony,

I am currently at a stage where I am implementing quest rewards upon quest completion. I intend to spawn a treasure chest as the quest reward. Therefore, I created a script that contains a method to spawn a chest near the player. I thought the most intuitive place to call this method would be through a UnityEvent in the 'successful' state of the quest on the Quest Machine window.

Unfortunately, I could not find the new method I have created in this UnityEvent dropdown (shown on attached image). Why is this so? If this is not the right place to call a method upon quest completion, where should we be doing it?

Code: Select all

        
        public void SpawnRewards()
        {
            GameObject player = GameObject.FindGameObjectWithTag("Player");
            foreach (GameObject reward in rewardsToSpawn)
            {
                GameObject rewardSpawned = Instantiate(reward);
                rewardSpawned.transform.position = GetDropLocation(player.transform.position);
                rewardSpawned.transform.LookAt(player.transform.position);
            }
        }
        
Attachments
spawnChestIssue.png
spawnChestIssue.png (54.96 KiB) Viewed 570 times
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Rewards

Post by Tony Li »

Hi,

UnityEvents can't call script methods directly because they don't have any context. If you add your script to a GameObject, you can assign the GameObject to the UnityEvent and then select the method.
Post Reply