I’m making an endless runner where there is roadblocks that should multiply or subtract the players points based on what the roadblock values are. What is the best way of identifying what those values are?
The best way as far as I am aware of, is to use a message with a value assigned, to the player script.
Firstly in player script
, create a new function
:
void UpdateHealth(int DamageTaken)
{
//Your code here...
}
Then in the prefab instance
(roadblock) script, get a refernce to the player
script through GameObject.Find.GetComponent<>
. Once you have a reference
, call the function
in the code where you detect collisions with the player. _ExpleVar.UpdateHealth(_DMGtoPlayer)
.
Step by Step
1: Create the function
in player script.
2: In roadblock script make a variable of the right class
for the player script.
3: In void Start
assign the variable.
4: Where you detect collisions with the player, call the function
.
Hopefully this helps, if you need any further assistance, just comment or message me.
Thanks! This helped alot!