- Home /
Picking up an object to allow power-up, using external script
I have been searching for a while now, to find out how to make my player transition to a flying mode when picking up an object. This flying mode came with an asset, but unfortunately I cant find a way to transition through the use of the object. In the PowerUp script I want the transition to be for 10 seconds and I realise that Couritine is needed for this, but I want to find out how to the transition first.
Here is the simple PowerUp script:
and here is what i believe to be the relevant part of the flying script: I would greatly appreciate help, because I am new to C#, thanks.
well it looks like it should work, or am i wrong? if you use a collider and tick the trigger toggle, add the pickupscript to the object and the flyscfipt to the player=> must be taged as player then it should work
@dan_wipf Thats what I thought as well, but it does nothing. The player doesnt levitate as he usually does when he flies.
Answer by Saiguru · Mar 07, 2019 at 12:33 PM
If I am understanding correctly, the player needs to pick up an object and when the player picks up, you need the player to fly and you need the transition from the normal state to flying state to be 10 seconds?
If so, your current code does not work because of the Update Method in the flying script, as it is still checking for the input.
@Saiguru Yes your are correct about the pick up effect. What would you suggest I change my Update method to? Sorry I am new to C#
Hi, the issue is the Update method and it checks input each frame, currently even if the player picks up the object from the Update method I still interpret that the Player has to press the "flyButton" and once that is checked the state changes whether to fly or not. So can you try moving the current if (fly){} else{} block outside the current if(Input.GetButtonDown(flyButton)) and try setting the boolean value for fly in the PowerUp script by creating an object.
Your answer
Follow this Question
Related Questions
coroutines : trouble editing and accessing the same public variable 4 Answers
4.6 C# change canvas dependent on value 0 Answers
How to make the Colour parameter in coroutine work with any anything with a colour variable. 2 Answers
After building move doesnt move 1 Answer
Can I use a raycast to retrieve information from the collider? 2 Answers