UI for sprite

I’m trying to get a sprite to be clickable and then a UI with options for that sprite (move, shoot, etc) but I’m running into some knowledge/other problems.

I figured the best way to do this is to have a child canvas that can but enabled when click on, but I’m having some problems getting it to come up, centered on the sprite.

here is the small script for the click:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ShipClick : MonoBehaviour {

public Canvas canvas;

	void OnMouseUp() {

	canvas.enabled = true;


The issue is that it doesn’t come up even if I drag the canvas onto the script. The sprite has a Box Collider 2d on it.


I’ve figured out that I can make the sprite game object have both a button and a canvas component but the only way to be able to see the ship with the canvas component is with a world space render mode. The other 2 render modes seem to make the sprite disappear.

why u don’t use game object ? u want to enable and disable it , right ?


where is this script ? i mean on what game object ? same canvas or another ui button ?

try this :

public GameObject CanvasGO;
void OnMouseUp()
{ CanvasGO.enabled = true; }