How can I input image to be my questions on my quiz game app. I've managed to have the image script but I can't see any images
Here is my code for the Game Controller which holds the data of the game.
Here's an image of the Game Controller
Game Controller will look like this
public Sprite quizImage;
public TSSimpleObjectPool answerButtonObjectPool;
public Text questionText;
public Text scoreDisplay;
public Text timeRemainingDisplay;
public Transform answerButtonParent;
public GameObject questionDisplay;
public GameObject roundEndDisplay;
public Text highScoreDisplay;
The problem is image does not show when i run the app. What is the problem?
"Image doesn't show" could mean multiple things. You really need to clarify.
But here are some quick fixes from my experience. (Common error: "Image doesn't show")
a)
Make sure you look at the parameters when looking at Unity. When you superimpose images in unity (ie putting a background with a image), it's a common issue that sometimes images cover each other. You have like 5 images/text in your picture... make sure your paying attention to z values.
b) You need to looking into prefabs. IE dragging an image into the hierarchy and dragging it back to assets usually does the trick. Get the prefab -> drag it into the public gameobject. Judging by how you haven't plugged in a sprite in your image means you can't to figure out how ton drag objects in.
Some documentation on prefabs
https://docs.unity3d.com/Manual/Prefabs.html
c) You're mixing up Sprites and GameObjects together. Look up differences between the two and post again.
d) Make sure you are not plugging in a blank sprite. If you want to use sprites, make sure you know how to attach to image to them. You can follow this tutorial down here.
https://docs.unity3d.com/Manual/SpriteEditor.html
Second of all, sprites are used in unity 2D, not unity 3D. They are 2D graphical objects... stop mixing up the two.
Hope this helped.
Related
I'm trying to make an application that has sprites going down the screen with numbers in them. The Text(Script) component only works for 3D objects. I've tried using Text Mesh and making that a child of the sprites but I need them to be instantiated as a Prefab. So when I load the sprite in as a prefab it loses it's relationship to the Text Mesh. Does anyone know of a solution that worked for them?
There are many ways to do it depending upon your requirement. I will show you two of the most basic.
1- Use 2D Sprite and TextMesh.
2- Use Canvas Image and Text Objects.
P.S First one, that is 2D Sprite can be Instantiated directly in the hierarchy but for 2nd(Canvas Image) you need to instantiate it inside the canvas obj means as a child of canvas object.
I want to make RPG game using Unity2d with the tile feature to draw the game map.
I created a new class inherited from UnityEngine.Tilemaps.Tile and overrided void GetTileData.
In void GetTileData I determine the sprite to show for each tile according to the tile's neighbors.
See the image below. The source image is input from the inspector. The input is only one image like this below. I don't want to make massive input images caus that totally mess up.
But then I have a problem. When in the game I have to extract certain blocks from the source image and combine them into a new sprite to show onto the map as a tile sprite.
Just want to know, if I have the 4 rectangles known, and want to combine them into a sprite like the image above, how can I do that?
There is no easy way to do what you want in code. Simply use a tilemap with smaller base tiles.
What I want
To create an effect like an slash in my 2D project. For that, I've an image in my assets already, and I want to draw it from top to the bottom, allowing it to be drawn in maybe half a second, progressively.
The idea is to draw it to create the effect of the slash itself, and the progressively mode is to "fit" the slash image itself, imagine the first one of the following link, that would be drawn from left to right.
To achieve that kind of drawing, the only thing that I've found is fillAmount for an Image, combined with the fillMethod.
The problem
The problem is that these methods are for the Image class, that it's not recommended for game drawing but only for UI.
Anyway, I've tried to do it this way, and I've not been able to do it, because the Unity environment didn't let me drag&drop my slash asset into the Image variable that I had created into my script. I thought that it may be because of the type of import, but also trying to import it with the other options resulted in nothing better.
The questions
Just answering one of these questions would solve my situation (or I think so):
How can I make Unity accept my image/asset into my Image object in the script?
Another way to create such effect using Sprite or GameObjects directly?
Method 1: You can use sprite sheet to create a 2D animation
1-1. Prepare a splash effect sprite sheet (an image map contains continuous action image), like
1-2. Change the sprite mode to multiple in inspector window
1-3. Slice the sprites in sprite editor
1-4. Multi-select the sprites and drag into hierarchy window, Unity will ask you to save this animation
1-5. You will get an animation GameObject
Method 2: If you can make it like a circular progress bar, check Radial/ Circular Progress Bar in unity3d
I am wanting to make a birds-eye view pixel-art game.
I currently have two sprite sheets set up, and split and whatnot
groundSheet and characterSheet these are split up into
ground_0_0_0 (A concrete floor)
ground_1_0_0 (grass)
character_0_0_0 (man idle animation frame 1)
character_0_0_1 (man idle animation frame 2)
character_0_1_0 (man run animation frame 1)
character_0_1_1 (man run animation frame 2)
character_1_0_0 (woman idle animation frame 1)
character_1_0_1 (woman idle animation frame 2)
character_1_1_0 (woman run animation frame 1)
character_1_1_1 (woman run animation frame 2)
The numbers after are a note as to:
first number - the main set of sprite animations (eg man)
second number - the animation set in use (eg run or idle)
third number - the frame of said animation.
(the ground has this as i plan to have animated grounds late on)
Now, I wish to make a script for the character (and ground alike) that has an editable value that is view able in the unity editor, for example how things like the sprite renderer has sprite, colour etc. Which dictates what first number to use (see above) what second number and the delay for the animation of the third number. This will then tell the sprite renderer what pictures to load and how quickly to load them. I also wish for the script to scan for the file starting with for example character_0_0_ and then count how many files after it, so it knows what to do when animating. I would like this script to be checking for a change in one of the variables viewable in the unity editor to change and as soon as it does it checks everything it needs for an animtion.
Something else could be done where there is only 1 box to edit in unity, which you put character_0_0_ or ground_1_0_ or something similar, and it checks everything that way (it also makes the script universal, and usable on the ground, character and walls (which I am adding later)).
This may seem confusing, but it make sense for me and many of you will probably mention a much easier way to do animations and such, but please only say these if it does what I want above.
For scripts and such my file layout:
/Assets
/scripts
ground.cs
character.cs
/sprites
characterSheet.png
character_0_0_0
character_0_0_1
character_0_1_0
character_0_1_1
character_1_0_0
character_1_0_1
character_1_1_0
character_1_1_1
groundSheet.png
ground_0_0_0
ground_1_0_0
(For some reason Stack overflow said the above was code, so i had to make it as that)
ground.cs and character.cs are the scripts in which I want to made as explained above.
In my object view thingy I have
Main Camera
ground
character
I am practically a newb to C# and JS I know bascially the grammar of C# (like where to use {} and put ; at the end of the lines). If you help me with this, i request that you explain the script, like use the // thing to simply explain what each command does, I know a few but not all of them. And I know someone is going to say it is really well documented in tutorial X and such, but most tutorials are not in unity 5 and while helping with the matter do not touch on it exactly.
Thank you for your help, if there is anything about this question/request that you do not understand (It is pretty complex) I will explain.
Maybe I am completely wrong, but it seems to me that you are trying to recreate an Animation system.
Is there a specific reason for which you wouldn't use Unity's animation system?
You can do everything that you describe here with it (change sprite, choose animation speed). And you would have almost no code to write. Just drag and drop you sprites in the editor for a start
EDIT - answer to first comment:
What you should do is create all the animations you need. Then in the animator, you choose which condition will trigger a transition to another animation (for instance, boolean jump is true will transition to animation jump). Then in your code you can call GetComponent().SetBool("Jump", true).
To have different character, you can create different gameObjects (one per character). They all have a different animator with animations specific to the character.
The other solutiojn if you really want one one gameObject and one animator is that you also add string condition to you animation (example, if character=="character1" and jump==true, transition to jump animation).
If I were you I would really focus on testing and learning all you can do with Unity animator. I can't think of a case were you would need to recreate the animation system yourself
Your question was long winded and hard to understand but ill try to help,
firstly if you want editable values in the unity editor I would Suggest using a serialized structure of information like this
[System.Serializable] // this makes it viewable in the inspector
public struct Sprite_Manager;
{
public Sprite[] Render_Sprites; // array of sprites to store sprites
public SpriteRenderer S_Renderer;
public float Anim_Delay;
}
public class Character : MonoBehavior {
Sprite_Manager SMG = new Sprite_Manager(); // instantiate a new instance of the struct
void Set_Sprite()
{
for(int i = 0; i < SMG.Render_Sprites.Length; i++)
{
SMG.S_Renderer.sprite = SMG.Render_Sprites[i];
}
}
void Update
{
Invoke("Set_Sprite", SMG.Anim_Delay);
}
}
Not sure if this is exactly what your looking for but this is one way you could setup a structure of sprite based information and use Invoke to setup some sort of delay when passing new sprites to the renderer.
I am trying to create a short animation of an object rotating in 3D space..I have all my images ready..I would like to know how I can change from one image to the other without the transition moves being shown
Thank you
Edit: What i mean is that instead of having a bouncing ball which all i need to do is move the ball in each frame, what if i had and object that in every frame I used a different image: eg. person facing forward, person facing facing right, etc...how can i do it without the image being shown as being dragged from the screen?
I hope I'm making sense
I whant to advise you look at Principles of Microsoft Silverlight Animation video by Jeff Paries on mix09. I shure it usefull and comprehensive overview of Silverlight animations.