I’m kinda new at Unity so I need help with this.
I referenced my player using RigidBody2D , but i wanted to add a Enemy and added a code the make like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spikes : MonoBehaviour {
Bboi_keyMove pm;
public GameObject spawnLoc;
private void Start ()
{
pm = GameObject. FindGameObjectWithTag("Player").GetComponent<Bboi_keyMove> ();
}
private void OnTriggerEnter2D ()
{
pm.rb.position = spawnLoc.transform.position;
pm.deaths++;
Debug.Log ("Player has died" + pm.deaths + "times");
}
}
so i made the enemy a trigger and added RigidBody2D for gravity but then I noticed that every time the enemy landed, my player would be sent to the spawn location.
i just want to know any solution/problem with the code or any way of changing they way of referencing just the player without interfering with the enemy.
(The Bboi_keyMove is my player movement.)