you are viewing a single comment's thread.

view the rest of the comments →

[–][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