- Home /
Duplicate Question
Problem with discovering if a character is on top or not
I'm making a TBS with a Hex-Grid and all was going failt well until I remeber that I needed to make something to impede the player character to move to the same place as an enemy, so I need to make some script where the tile tells that there's someone on top of it, but I don't have any idea of how to do it. The grid is formed of hexagon and those are formed of 6 plane objects, the character is simply a cube that moves to the selected hexagon and I would like if it was done in a way that all characters could use the same script. I'm fairly newbie on programming and sorry if I wrote something wrong (english isn't something that I'm very proud of), but thanks for any helping.
Use OnTriggerEnter OnTriggerEnter is called when the Collider other enters the trigger.
This message is sent to the trigger collider and the rigidbody (or the collider if there is no rigidbody) that touches the trigger.
using UnityEngine;
using System.Collections;
public class ExampleClass : $$anonymous$$onoBehaviour {
void OnTriggerEnter(Collider other) {
Destroy(other.gameObject);
}
}
For more information about OnTriggerEnter https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
What exactly is going on when I implement Update(), and other messages in MonoBehaviour 2 Answers
Yet Another Bullet Decal Problem 0 Answers
Flip over an object (smooth transition) 3 Answers