I’m making what is at this point a 2D Mario clone and want to send a message initiating a method on an enemy script. The most efficient way I can think to do this would be to do as so.
I have a child object with a box collider and script for ground checking with this C# code.
using UnityEngine;
using System.Collections;
public class MarioFeet : MonoBehaviour {
void OnControllerColliderHit(ControllerColliderHit hit) {
var hitVec = hit.point - transform.position;
if (hitVec.y < 0) {
Debug.Log("Boop");
hit.gameObject.SendMessage("MarioStomp");
}
}
}
Then on my npc object a sprite renderer, box collider and behavior script:
using UnityEngine;
using System.Collections;
public class npcBehavior : MonoBehaviour {
void MarioStomp() {
Debug.Log("Boop-Bop");
}
}
I’m not logging what I want but I’m getting a warning, “The referenced script on this Behaviour is missing!”
Do I need to find the game object in my script and get component? I’m not sure exactly how the hit or send message works as I’m new to unity would like to at least know where to look as I’ve found myself alone and down an alley I don’t fully understand.
P.S. this is my first unity question so if there is anything I can do to make my question better I’d love to know.