#Disable coin interaction during animation

1 messages · Page 1 of 1 (latest)

proven python
#

@soft kelp I only should need the coin script

soft kelp
#

That's my coin script.

#

I have another script that moves the coin towards the player aswell.

proven python
#

Ok I'll need the animation script too

#

also, to make it easier, enable all notifications in this thread

soft kelp
proven python
#

Ok, so what we're gonna do is make a reference to your animator in GoldTicket
Then, we're gonna want to check what state the animator is currently in so we're going to use Animator.GetCurrentStateInfo (returns AnimatorClipInfo[]), to get the clip name you're just gonna get the .clip.name from the animatorclipinfo's 0th place

soft kelp
#

So I disable that script if the animator is playing an animation?

soft kelp
#

If it make it easier, the coin only has one animation

proven python
proven python
soft kelp
#

Alright. I'll try GetCurrentClip

soft kelp
proven python
#

which means they'll only be updated once when you start the program

#

ticketcontroller is fine

#

ticketchestclipinfo, length, and ticketchest shouldn't be in start though

#

Why are we getting the length of the clip?

soft kelp
#

How would I say "If animation is playing" , "return;"

soft kelp
proven python
#

by the way, you're destroying the gameobject before getting the component and adding money

#

you can't do anything after destroying the object the script is on

soft kelp
#

Oh? The script worked fine. Would it be better to just switch it though?

proven python
proven python
soft kelp
#

Alright.

proven python
#

It only worked because of luck in the garbage collection cycle

proven python
soft kelp
#

I changed all of my scripts that had it this way. Luckily it was only the coins.

proven python
#

you shouldn't need this part anymore in start

proven python
soft kelp
proven python
soft kelp
#

Not previously, due to some kinks in my coin script.

proven python
#

im assuming you dont know how to use coroutines, right

#

we're simply just going to wait a little bit after the coin appears to make it be able to be picked up

soft kelp
#

Generally not.

proven python
#

we're not gonna care about the animation at all

#

upload your current coin script

soft kelp
proven python
#

Still working on it one sec

soft kelp
#

Take your time. I'm grateful that your helping me in the first place haha.

proven python
#

i consider this my volunteer work :p

#

@soft kelp what is "cam"

#

you shouldn't use abbreviations in variable names because it makes it hard to understand for others, especially without a comment

soft kelp
#

Ah, cam is my player. My bad, I should've mentioned that.

proven python
#

Ok, I'm going to rename "cam" to player in the script

soft kelp
#

That's fine.

proven python
#

obviously a lot of the comments you can delete after you understand what everything does

#

but you should keep them until you know 100% that you understand what all of the code means

soft kelp
#

Yeah. I'm reading through it now.

proven python
#

if you have any questions feel free to ask

soft kelp
#

I'm only asking because it'd be easier to edit if it showed up in the inspector. Just for convenience' sake, but if it's not then that's fine.

proven python
#

Ok how about I teach you something else

soft kelp
#

Sure.

proven python
#

you know how you have public GameObject player; at the top now?

soft kelp
#

Yeah.

proven python
#

you don't need it to be public, you don't need a script to access your coin script and get the player gameobject from it

#

but you want it to show in your inspector, right?

soft kelp
#

Yes, so I can assign it.

proven python
#

Well, theres this cool thing called [SerializeField] that you put above private variables to show them in the inspector

#

so you can make your player gameobject private, and then put [SerializeField] above it so you can edit it in the inspector

#

"serialize" basically just means "save"

soft kelp
#

Thanks! I'll study the references a bit. I think I've seen it before.

soft kelp
#

@proven python I've run into an issue. Using [SerializeField] I've determined that "isInvincible" is true before it's enabled, but it becomes instantly false as soon as the coin is enabled no matter how high I set "invincibilityDuration"

proven python
#

or code editor

soft kelp
#

Visual Studio

proven python
#

do you know how to make a breakpoint

soft kelp
#

No, I haven't heard of that yet.

proven python
#

alr

#

do you have visual studio correctly set up to attach to unity

#

it should say this at the top of vs

#

@soft kelp

soft kelp
#

Yes, I'm looking for it. One issue is that I'm using an older version of VS. I tried downloading the newer releases, but they refused to work on my laptop.

proven python
soft kelp
# proven python

I've researched it a bit. I think I haven't installed "VS Tools for Unity" and I can't find a download. I'm going to try and re-install a newer version of VS. I'll come back to you when it's done.

soft kelp
#

I see them.

proven python
#

(i have visual studio code selected, but download visual studio editor)

soft kelp
#

I've hit 'update'.

proven python
#

"IDE Configuration"

soft kelp
proven python
#

you can make the game pause when it gets to a part of the script by adding a breakpoint

#

right click > breakpoint > insert breakpoint

soft kelp
proven python
soft kelp
proven python
soft kelp
proven python
#

it should stop right before the coin (is supposed to) become invincible

#

sorry i was a bit busy

soft kelp
proven python
soft kelp
#

Both my VS and Unity Editor bars are red. Does that mean I attached it correctly?

proven python
#

yes they should be attached

soft kelp
proven python
#

player settings -> other settings: change API Compatability to 2.0 (if already 2.0+, change to subset then back to 2.0)

#

close & re-open visual studio and press build -> clean solution, then build -> rebuild solution

#

@soft kelp

soft kelp
#

Wait, I think something happened.

#

When I tried to open my chest, I got kicked out of the editor.

proven python
#

yes, thats what the breakpoint does

soft kelp
#

What should I do now?

proven python
#

now go to vs and hover over isInvincible

#

what is it's value

soft kelp
#

"true"

proven python
#

wait why is isInvincible = false

#

it should be true by default

soft kelp
#

That's after the coroutine has ended in your script

proven python
#

ohh alright

soft kelp
proven python
#

ok well i think whats happening is that it continues after starting the coroutine

#

so simply change

    // This coroutine 'waits' for 'seconds' amount of seconds
    IEnumerator Wait(float seconds) { yield return new WaitForSeconds(seconds); }

to

    // This coroutine 'waits' for 'seconds' amount of seconds
    IEnumerator Wait(float seconds) 
{ 
yield return new WaitForSeconds(seconds); 
isInvincible = false;
}
#

and get rid of the isinvincible after startcoroutine

soft kelp
#

I think it works! I'll come back to you if I encounter any issues. I didn't expect this to be so fragile lol.

#

Also thanks for teaching me about Breakpoints, Coroutines, Debugging etc . I really appreciate it!

soft kelp
proven python
#

wha

soft kelp
#

I'm really confused aswell.

proven python
#

oh add && other.CompareTag("Player") to the if statement in ontriggerenter

proven python
#

yeah

#

make sure your player has a player tag

#

hey wait

#

you have isInvincible = false in the if statement

#

was it like that before

soft kelp
#

Oh, before it was !ifinvincible and I tried messing around a bit to solve the problem. I changed it around a minute ago.

proven python
#

!isInvincible or isInvincible == false

#

one equal sign SETS it to false

soft kelp
#

I changed it to ! and == but no dice. Even with the comparetag, it's still letting me pickup the coin if I collide with it (I'm using SerializeField to check if invincible is true and it is)

#

Here's everything on the inspectors of my object (Top) and it's parent (Bottom)

#

"ChestGold" is the script that we're doing now
"TicketCamera" is a billboarding script
"TicketMover" is a magnet script

proven python
#

i gotta be missing something

#

send the whole script as you have it rn

#

@soft kelp

soft kelp
#

Alright

#

@proven python

proven python
#

ok i think i misunderstood how awake works

soft kelp
#

How my chest works is that it enables the coin when the player interacts with it, in case I forgot to say.

proven python
#

yeah my method would work if your chest instead instantiated a coin

soft kelp
#

So the script needs to run as soon as the coin is enabled, not as soon as the game starts* I’m not sure that’d be done though

soft kelp
proven python
#

use OnEnable() instead of awake

soft kelp
#

void OnEnable ?

proven python
#

yes

soft kelp
#

I don't think that's the problem though. The game is definitely registering it as "isInvincible", it's just that it doesn't really know or care what "isInvincible" means (somehow).

soft kelp
#

Well, @proven python . It works now. I don't know what made it work, but it works. Thanks for sticking with me!

soft kelp
#

Some guy told me to put a "Debug.Log" in the "OnTriggerEnter" and it works now

#

I guess you can close the thread now, if you want

#

@proven python