I have 4 identical sprites that don't do the same thing, Why? - mit-scratch

I have four identical scratch sprites, but only one of them do what I expect and I need to know why so I can continue with my project
I have tried reloading the page multiple times but it still won't work
When (Green Flag) clicked
forever:
if touching mouse-pointer? then:
set (Enclosure Hover) to 1
else:
set (Enclosure hover) to 0
I expect this to change Enclosure Hover to 1 when the mouse is touching it but it doesn't change it at all.

If the variable is global, all sprites will compete to change it. Hope that helps!

You have to add the code to all the sprites that you want. Duplicating a sprite, then adding code to one of the sprites does not add the code to every sprite.

One way is to add code to one sprite, then duplicate the sprite with the code in it. The code will be duplicated along with the new sprite.

You will need to duplicate the sprite only after the sprite has the code in it so that the 4 sprites do the same thing. I guess what you have been doing is to duplicate the sprites then adding the script into only one of them.

Related

My sprite cover the edges of other sprite Unity 2D

I'm working on a procedural world generation in Unity 2D. But when It spawns my blocks, blocks cover each other. What could be the possible problem? How can I fix it?
Thanks for your help.
Screenshot:
screenshot
It might be because you made the boxcollider2D on your blocks a little too small.
Try to fit the collider perfectly with the edges of the block
Okay, finally managed to solve it. For future people, here's the solution:
So when you export your sprite from Photoshop or whatever program you use, you export it with a preferred size (ex. 128×128 px).
What you need to do is, go ahead and click your .png file in Unity. In the inspector window, you will see an option called "Pixels Per Unit". You have to enter the correct sprite size there.
Apply the changes, and there you go!

Prefab in unity appears in a wrong location when drag and dropped

I've created a prefab of a trophy in unity. But when i drag and drop prefab to the scene, it appears in the wrong location. You can see at the photo where i drop it(red circle), and where it appears(green arrow).
Same happens when i instantiate it with a script. it appears righter and higher than i click.
As far as I can see, there is an animation in your prefab.
Make sure no coordinate points are registered in this animation clip.
It looks like there is an animation on the trophy. I think what happened was you moved the prefab with recording toggled on and thus, the outcome would be like that. All you have to do is edit the prefab's animation and at the start of the animation, set the position to 0 on all axis. If the problem is still there, check the script, maybe there's something wrong with that? Also if you're still stuck, edit your post with the script. And when I say 'the script' I mean the script that instantiates the prefab.
I hope this helps in some way! :D

Sprite dislplays all of the frames without acting like an actual sprite

So, i've been trying to make a videogame on unity, and i made my first sprite on piskel. Exported it as PNG but can't seem to make it work on Unity. I imported it as a new sprite and even selected sprite (2D and user UI) on the menu.I selected 2D sprite but it doesn't work. It's just like if I put an image there, and not a sprite.It stays still I even tried using another sprite format More rows
I can't find anyone else with the same problem out there on the internet, so help would be much appreciated. Thank you.
Selecting 2D sprite isn't the full story. You will also need to make the sprite "multiple" instead of "single" and split it up in the editor (now available in the package manager).
That will split it up into frames for you, then you drag and drop a single frame.
https://docs.unity3d.com/Manual/SpriteEditor.html

Unity 5.3.8 Animator - Glitch?

I created a bunch of non-AI animations for enemies that do basic back.forth or up/down motions. Everything was working perfect until I started working on the Boss of the level. The boss has his own tag "Boss" and enemies have their own tag as well. Anyway, the problem is when I click start, every enemy leaves the game board. I can see them animated above the game board still doing their routines.
Any clue as to why this happened and how to fix it? I'd really, really hate to have to scrap all the enemies and start from scratch...
I used the Animation tool inside unity.
Extra Note: I created an EMPTY and moved all of my enemies into that Empty object to clean the hierarchy panel up. The animations were fine before this.
************** Currently Resolved **************
Whew! Okay, so apparently Unity doesn't like it when you move your animated stuff into an empty AFTER being animated. I FIXED them by simply removing them from the EMPTY that I had placed them in. However, I'd still like to know why this is. So any useful resources, links, manuals, personal insight/observations or anywhere I can read up on this would be appreciated!
Here is an explanation what happened:
The moment you dragged them all into the empty GameObject I guess this object probably wasn't placed on 0,0,0 in the Scene.
So Unity automatically changed all the local position values of your enemy items to fit the current position offset to the empty object.
Result: In the editmode they don't change their actual global position in the scene but their local position. This is supposed to happen if you just want to organize stuff.
However, now when you start the game and the animations are played, the animators change all the local positions to whatever is stored in your animations.
Result: all objects jump back to their original localPosition which had an offset to the empty GameObject.
To solve this make sure the empty GameObject is at position 0,0,0 and optimally has rotation 0,0,0 and scale 1,1,1 before you drag anything into it.
Easiest way to achieve that is by clicking reset in the empty objects Transform component before starting to drag stuff into it.

How to merge two background sprites in Unity so that there won't be a line between the merging sides?

Hello guys, I am making a 2D platformer game in which I will be adding background sprites. And while doing so, I will be joining many(let's say two) sprites to make it look like one long background. However, when I join two background sprites, a line is visible at the joining point, making it evident that I merged two sprites there. How do I make it look like it is a single image? How do I remove the line between them? Please help me fix this. Any help would be very much appreciated.
I struggled with this problem too, i solved it indirectly by creating a third joiner sprite that is a child of the first sprite and placed at its end (covering the line). As the backgrounds move the third sprite always covers the joining line. The joining sprite can be a a drawing of anything eg clouds, wall, etc