How to create a selectable menu off a cursor going over a game object?
We are trying to make a 2-d strategy game similar to the older game Advanced Wars for the Gameboy. We want to make it so when our cursor goes over our unit and we press space, it will select the unit and a list of options will appear that will include things like attack or move. Currently, we have the cursor working in being able to move and it able to measure the distance between it and the unit. We do not know how to make a menu appear when the cursor is the unit. This is what we have so far:
using UnityEngine;
using System.Collections;
public class CursorMove : MonoBehaviour {
private float speed = 6f;
private Vector3 pos = new Vector3();
private Transform tr;
private Vector3 unitPosition;
void Start() {
pos = transform.position;
tr = transform;
unitPosition = GameObject.Find("Rifleman1 2").transform.position;
}
void Update() {
if (Input.GetButton("Up") && tr.position == pos) {
pos += Vector3.up;
}
else if (Input.GetButton("Left") && tr.position == pos) {
pos += Vector3.left;
}
else if (Input.GetButton("Down") && tr.position == pos) {
pos += Vector3.down;
}
else if (Input.GetButton("Right") && tr.position == pos) {
pos += Vector3.right;
}
transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
float dist = Vector3.Distance(tr.position, unitPosition);
if ((dist < 0.5) && (Input.GetButtonDown("Select"))) {
//here we want to put in the code to make a selectable menu appear
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612065232im_/https://answers.unity.com/themes/thub/images/avi.jpg)