How to check when certain method from another class is called? [Newbie question]

EDIT: SOLVED;
All i had to do was to add:
csharp** **public JumpBars playerJumpScript;** **
to the PlayerControler and add

playerJumpScript.<call method that removes jump energy>();

to the PlayerControler
as well as create method of removing energy from the JumpScript :slight_smile: Lesson learned!

First of all, i have asked this question before on “Answers”, but it has been waiting for moderation :frowning: i am new to forums and i dont know how everything works, so if i should close the question somehow, pelase, let me know how.

TL;DR at the end.

Hello world! :slight_smile:

Hi. Okay, so first of all - please, understand me. I have no coding knowledge, no idea whats going on on unity. No background in anything related to coding.

I know that people odnt like whne questions that have already been answered are asked, however, i did not find any specific help on youtube, google or unity forums.

My situation:

I have created “roll-a-ball” game, and decided to add certain features. First of, after completing the tutorial series from youtube, i decided to make my ball JUMP. Had some problems wiht “OnColiisionStay” “isGrounded”, watched some more tutorials, decided to use “RayCast”.

Now, i have added HP and ENERGY bar (took me like 8 hours x.x’'). but its in different script.

Now, the good part is, the playercontroller, which has “JUMP” void checks for the information on player energy by checking “public static float energyshown” from JumpEnergy script, that also shows the amount of energy left on GUI.

I also made some adjustments and it wont allow me to jump if energy is <75.

BUT, i want to make it so “JumpEergy” script, to recignize when “PlayerController” uses “void Jump” command, and then it would adjust the amount of energy accordingly. I know how to add/remove amount oif player energy, but i can’t think of how to check when “Jump” called from another script. :c
Tl;DR;
Class 1
Void “jump”
need to let
Class 2 know when is “jump” from “class1” used.

If anyone could help me understand how this works - i would be very thankful!

2 Likes

Glad you got it, and thanks for updating your post with the answer — this may help other newbies who have the same question later!

1 Like