Hello guys
I’m new to unity and coding in general , and trying to make my first game
So I managed to make the enemy show “death animation” after jumping on its head, but it still moves untill it’s destroyed
Tried getting to the scrips of the enemy from the player’s, but I get a console error- object reference not set to an instance of an object (line with EnemyMove.speed)
that’s the player’s script (cut it short for ya, tell me if I need to add the full script)
public class PlayerMovement : MonoBehaviour
{
//kill enemies
public GameObject jumpkill;
private Animator DieAnm;
private EnemyMove EnemyMove;
// Start is called before the first frame update
void Start()
{
//enemy
EnemyMove = GetComponent<EnemyMove>();
DieAnm = jumpkill.GetComponent<Animator>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Stomp")
{
Destroy(jumpkill, 1);
DieAnm.SetTrigger("Die");
EnemyMove.speed = 0;
}
}
}
that’s the enemy script
public class EnemyMove : MonoBehaviour {
public float speed;
public Vector2 movement;
public Animator DieAnm;
// Start is called before the first frame update
void Start()
{
speed = 1 * Time.deltaTime;
movement = new Vector2(speed, 0);
}
// Update is called once per frame
void Update()
{
transform.position = new Vector2(transform.position.x + movement.x, transform.position.y);
if (transform.position.x >= 41)
{
movement = new Vector2(-speed, 0);
transform.localScale = new Vector2(-0.45f, 0.45f);
}
if (transform.position.x <= 34)
{
movement = new Vector2(speed, 0);
transform.localScale = new Vector2(0.45f, 0.45f);
}
}
}