I’m sorry if this isn’t the correct thread to put this in (I have no clue if this is a scripting issue or some other issue, otherwise I would’ve put it in scripting thread), I wasn’t quite sure where to put it but I’ve attached a video showing exactly what my issue is however I’ll give you a quick rundown.
For my games Menu Screen I want to have the games characters run across the bottom of the screen infinitely. The way I have it setup is, I’ve added a RigidBody2D and a BoxCollider2D onto the wizard prefab, I’ve then created a Empty Game Object, gave it a BoxCollider2D and then named it Barrier. I then created a very small script to handle collisions and attached that to the barrier (I’ll attach the code at the bottom). Then the last thing I did was create another empty Game Object and named it Spawn Location. What’s suppose to happen is the Wizard’s running animation is suppose to make the wizard run across the screen, once the box collider I’ve attached to it hits the barriers box collider, the script runs. It then Instantiates another Wizard Prefab at the Spawn Location game objects position, sets the correct rotation so the characters animation makes him run the correct direction, then destroys the previous wizard game object, and this repeats infinitely.
However, for some reason when the wizard prefab is instantiated, the box collider on it is too small so it’s giving me a little warning on the component saying it’s too small to detect collisions. I’m not sure what the issue is or why it’s doing this. Thank You!
Video:
Collision Script:
using UnityEngine;
public class MenuColliders : MonoBehaviour {
[SerializeField] Transform spawnLocation;
[SerializeField] Transform wizardPrefab;
//[SerializeField] Transform vikingPrefab;
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.gameObject.tag == "MenuWizard") {
var wizard = Instantiate(wizardPrefab, spawnLocation.position, Quaternion.identity);
wizard.rotation = spawnLocation.rotation;
wizard.gameObject.tag = "MenuWizard";
Destroy(collision.gameObject);
}
}
}