- Home /
Sprite Sheets Broken, Cannot Drag & Drop Sprites
In this scene I have three buttons, created in code:
using System;
using UnityEngine;
/// <summary>
/// Title screen script
/// </summary>
public class MenuScript : MonoBehaviour
{
public Texture newGameButtonTexture;
public Texture loadGameButtonTexture;
public Texture exitGameButtonTexture;
void OnGUI()
{
// Draw a button to start the game
if (
GUI.Button(
new Rect(
Screen.width / 2 - (newGameButtonTexture.width / 2),
(2 * Screen.height / 3) - (newGameButtonTexture.height / 2),
newGameButtonTexture.width,
newGameButtonTexture.height),
newGameButtonTexture)
)
{
// On Click, load the first level.
// "Stage1" is the name of the first scene we created.
Application.LoadLevel("Stage1");
}
// Draw a button to Load a game
if (
GUI.Button(
new Rect(
Screen.width / 2 - (loadGameButtonTexture.width / 2),
(2 * Screen.height / 3) - (loadGameButtonTexture.height / 2),
loadGameButtonTexture.width,
loadGameButtonTexture.height),
loadGameButtonTexture)
)
{
// Load the game
throw new NotImplementedException("Load Game not yet implemented.");
}
// Draw a button to quit the game
if (
GUI.Button(
new Rect(
Screen.width / 2 - (exitGameButtonTexture.width / 2),
(2 * Screen.height / 3) - (exitGameButtonTexture.height / 2),
exitGameButtonTexture.width,
exitGameButtonTexture.height),
exitGameButtonTexture)
)
{
// Exit the game
Application.Quit();
}
}
}
I also have a sprite sheet, set to multiple, and I've cut the three buttons out of the sprite sheet using the sprite editor. All three button images show up in the designer as expected.
However, when I try to drag and drop the sprite textures into the script I get a "No" symbol in the designer. This worked just fine when I had one button, as a stand alone image. Is this an issue with sprite sheets? Am I doing something else wrong?
P.S. yes, I know the button spacing is wonky, I'll fix that.
Your answer
Follow this Question
Related Questions
Sprite sheet not visualized correctly 0 Answers
Sprites become blurry after automatic slice 3 Answers
What is the most Unity-compatible way to import sprite animations? 1 Answer
How to create animated "sprites" in a 3D environment 1 Answer
Using a single element(texture) of a sprite sheet in shader? 0 Answers