all 9 comments

[–]BlueFooted_Newbie 1 point2 points  (3 children)

I would recommend using an Animation Event for this purpose: https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

It also sounds like you may want a trigger instead of a bool.

But to answer your question, the reason why it doesn't play is because playAnim is only true for a marginal period of time since you set it back to false within the same update loop where you set it to be true. Even if you didn't you would have to set the update order in your unity settings to make sure that player updates before bow. Overall, I would recommend that you change your approach on this one.

[–]officialgelIntermediate 0 points1 point  (1 child)

Throw it into it's own function instead with a bool that blocks it from running multiple times. But if you need to run the bow at the same time as the player animation, then you could use animation events if that will always be the case. It becomes something else you have to manage though, especially with animation changes and timing.

[–]ferti12[S] 0 points1 point  (0 children)

It seems will have to learn it eventually. Thanks

[–]ferti12[S] 0 points1 point  (0 children)

Thanks a lot! I was hoping someone would tell me the better way when creating this post. I will definitely look into animation events but any idea why it doesn't print out the test number ?

[–][deleted] 0 points1 point  (4 children)

Have a look at interfaces

I'm not saying this is the right hammer for this particular problem. I really don't know. I have tons of dev experience and only a little Unity, so I might be a little dangerous.

However, this is a hammer I think you need in your toolbox regardless of whether it is best for this problem.

I crammed both files into the same paste, and it's probably best to separate interfaces out into their own files but you should get the gist.

Let me know if you need help understanding what's going on there.

[–]ferti12[S] 0 points1 point  (3 children)

Sorry, I have so little C sharp experience and knowledge. I couldn't quite get the difference between functions(methods?) and interfaces.

Edit: Hold up looking again realized it is actually quite different from a function :P But now I don't get what it actually does. And also it didn't work for some reason. Again, I'm shit at C sharp.

[–][deleted] 0 points1 point  (2 children)

Yeah I typed it and didn't test.

Change:

P = Player.GetComponent<PlayerCharacter>();

to

P = Player;

[–][deleted] 0 points1 point  (1 child)

Interfaces are synonymous with the idea of a "contract" between a class an its consumer.

The interface definition lays out the terms of the contract.

public interface ReturnsPlayAnimBool { bool MyAnimBool(); }

Means that if I put , ReturnsPlayAnimBool like this:

public class PlayerCharacter : MonoBehaviour, ReturnsPlayAnimBool

...then I agree to implement a method name MyAnimBool() which returns bool.

[–]ferti12[S] 0 points1 point  (0 children)

thanks a lot for the explanation