Hey there,
I have the following situation:
I got a GameplayManager script like this:
public class GameplayManager : MonoBehaviour
{
public Transform spawnPoint1;
public Rigidbody2D player;
void Start()
{
Instantiate (player, spawnPoint1.position, spawnPoint1.rotation);
}
....
}
There is a prefab assigned to the “player” variable there is an empty gameobject assigned to the spawnPoint1 variable.
This script-component(GameplayManager) is attached to the camera component.
On my “player” prefab i assigned a new script component “PlayerManager”:
public class PlayerManager : MonoBehaviour
{
Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D> ();
}
void Update()
{
}
public void Jump()
{
rb2d.AddForce (new Vector2 (rb2d.velocity.x, 500f));
}
...
}
Next i added a Button to my canvas and assigned a Event Trigger:
Value: “Player” Prefab
Select: PlayerManager.Jump()
When i press the button in the game, no force is applied to the rigidbody of the player prefab.
I simply dont know why…any help or advices?
Thansks and Greetings