Hi :)
i am making a 2D game were the player can jump on enemies and kind of bounce of them if that makes sense. Whenever i try to jump of a enemy i don't get the "bounce" and i get a error
ArgumentNullException: Value cannot be null. parameter name: Source
Enemy.JumpedOn () (at Assets/Scripts/Enemy.cs:23)
PlayerController.OnCollisionEnter2D (UnityEngine.Collision2D other) (at Assets/Scripts/PlayerController.cs:100)
This s from playercontroller.cs:100
private void OnCollisionEnter2D(Collision2D other)
{ // Fiende och kollison med fiende
if (other.gameObject.tag == "Enemy")
{
Enemy enemy = other.gameObject.GetComponent();
if (state == State.falling)
{
enemy.JumpedOn();
Jump();
}
protected virtual void Start()
{
anim = GetComponent();
rb = GetComponent();
death = GetComponent();
}
This is from Enemy.cs 23
public void JumpedOn()
{
anim.SetTrigger("Death");
death.Play();
rb.velocity = Vector2.zero;
rb.bodyType = RigidbodyType2D.Kinematic;
GetComponent().enabled = false;
}
↧