First of all, I know these questions might sound stupid but please take a moment and try to explain me as I am a beginner.
I was waiting for 4.3 version from some time. I am trying to make a simple 2D Point and Click game. Actually I want to convert my previous games to Unity in order to learn it. I already mastered some easy tasks like reading an XML file (all my scenes/levels are in this format) and check mouse input to see if click on a sprite (from a previous entry in this forum).
But I still cannot figure it out how to load an image and assign it to a sprite… It must be a very easy task.
Question 1:
I have my Sprite object: ImageScene and MainCamera
What should I write in my CS script to be able to load an image (jpg or png) when I do something in my game. (clicking on a particular hotspot or pressing a button). An example of a code which is changing the ImageScene sprite would be useful.
Question 2:
How the heck is the Unity coordinate system working?
My game resolution it’s fixed (eg.: 1280 x 768 ) and I want to be able to render a sprite/image to a specific x,y position…
You should create your sprites within Unity first. Then you’ll have the ability to reference them in code. To assign game sprites in code simply create a public reference variable to your sprite, assign it in the editor, and then back in the code you’ll be able to set the sprite property of your sprite renderer to the variable you created and it will load that particular sprite.
Another way would be to just create your sprites in the editor, drag them onto the scene and create prefabs from them. Then, in your code, if you want a particular sprite to appear somewhere on screen, you’ll be able to instantiate the prefab either by name or use another reference variable.
I hope this wasn’t too confusing. I’ll be doing some video tutorials soon.
Coming from a different language, with no interface to deal with, and confortable with that, I’m also interrested about thoses two ‘simple’ issues.
I guess that what Ravl means is that he do NOT want to have to use the interface to read bitmaps but load them by scripting only. When you handle a game with hundred, if not thousand of files you do not really want to pick them one by one if you already have them listed in xml
I already have all my level data into the XML files. There are A LOT of files involved in the project and it’s impossible to make prefabs for every of them.
Also I cannot find anywhere in the documentation the “Load Image” function for my sprite…
I guess we will have to wait for those tutorials, unitylover?
I just checked out your “my games” link – are you doing a “Hidden Objects” game?
If so, I would personally suggest taking the time to do it in Unity – with prefabs and all. I get that it’s a hassle to set it up considering you’ve already done it in another method, but I wouldn’t be surprised if you spend more time trying to get your current work compatible with unity than you would to re-do the import of your images in unity.
Once in unity, a hidden objects game would be one of the most simple games to set up and make, since it’s literally just dragging and dropping objects into place.
Yes, I am in HOPA games for now. I also want to learn Unity for other type of games, but my next project will be a new adventure/ho game.
I waited for this Unity release to start using it, but it’s still quite difficult for guys like me to start with. I really want to use it, trust me. But even though I asked how to do some ‘simple’ things still can’t figure it how. No one is sharing any code for that and I cannot find tutorials for my kind of issues.
@Ravl that’s exactly the same for me. I’m just trying out everything / playing around and then asking the things I have no clue about how to figure out here.
If you really want to get on board with Unity 2D then I suggest you take the time to learn how things are done using only Unity. A lot of time could be wasted writing proprietary code. If you really want to harness the power Unity offers then it will be totally worth the time invested to bring your assets inside the environment. I’ll post some videos soon to show how much benefit you gain.
It’s often best to have objects as references, using public variables in the inspector. This has a number of benefits, including Unity automatically excluding unused assets from builds, and you can move/rename objects to your heart’s content without having your code break (or having to touch the code at all). Especially for sprites, since if they’re in the Resources folder they won’t work with the auto-atlasing for whatever reason.
The next thing people usually say is “but I don’t wanna drag 50 million things onto arrays in the inspector one at a time”, and the good news is you don’t have to. The trick is to use the lock icon. So you select the object holding the array, click the lock icon, and now select all 50 million sprites and drag them onto the array all at once. Then click the lock again to unlock.