Hi
I’ve got the code for the game in a dll. I’ve come so far that I’ve connected it to a script and gained response in the console, so it works so far. But I can’t find out how to display any graphics. If I understand it correctly I must do this within the script connected to the dll, where all the info is.
How do I load my graphics from within the script?
How do I draw the sprite?
I’m an experienced programmer, but I’m completely new to Unity and I am so excited to learn more.
The game is 2D and will be like looking down on a map.
I first started to do the GUI in Windows XNA and I had the basics in an hour, but I felt Unity was a better choice. Still I am frustrated to not have any visuals up and running yet.
No, it is not a text game. I need to draw sprites, but the info about where and what to draw are found in the dll - like tile 0,0: ground, explored - so based on what I’ve understood I need to create them in code and not create them in Unity’s editor. I’ve found out how to create a sprite but I’ve not been able to find out how to:
load my own graphics within the script file that creates the object from the dll
draw a sprite within the script file that creates the object from the dll
I know the connection to the dll works since I wrote text from it into the console, but I want a graphic interface of course. All I get is the standard view with a blue sky and a grey ground. My game is gridbased and will be seen as a map from above.
No GUI is within the dll. Only the “what is happening”-code. The dll contains for instance the map telling me what is on a square but it does not in any way contains any graphics. That was what I wanted to add with Unity.
This is the code in XNA that I want to know the equivalence in Unity. I’ve found the “Draw”-place, but what I can’t figure out is the green text below.
// Background map
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
for (int x = 0; x < this.game.City.Map.Width; x++)
{
for (int y = 0; y < this.game.City.Map.Height; y++)
{
Area area = game.City.Map.GetArea(x, y);
this.DrawArea(area);
}
}
spriteBatch.End();
}
private void DrawArea(Area area)
{
if (area.State == AreaState.Explored)
{
spriteBatch.Draw(this.ground, rect, Color.White); <== this.ground is a 2D texture that is put into the rect. This I want to do in Unity in some way but can’t figure out how the sprites work and how to create them in script/code like this.
}
else if (area.State == AreaState.Invisible)
{
spriteBatch.Draw(this.invisibleground, rect, Color.White);
}
else if (area.State == AreaState.Visible)
{
spriteBatch.Draw(this.visibleground, rect, Color.White);
}
}
}
That would be rendering into texture. It’s possible in Unity but not very common, and there are usually better ways. If it’s terrain, just draw it all even if it fills the entire screen, and draw UI on top of it.
Yes, thank you, maybe so, but I need some examples in how to do to this. I’ve checked some of the tutorials that seemed relevant but they were all about the editor way to do it. I can’t seem to find how to draw niether sprites or background in code.
It sounds like a very typical game like Starcraft? For that you really don’t want to render into texture. It’s only when you need to write custom shaders, full screen blurring or something, and even then it might not be required.
I must write extremely unclear or ask a very stupid thing… Maybe I have the answer right before my eyes and don’t see it, but for the moment, I am stuck in the fact that I have a script talking to my dll and in that script I need to create the sprites, background and all that, based on the info found in the dll.
You all give me very friendly advice, but the fact is that I can’t find any code examples on how to do either of what you suggest if it is not done in Unity’s own editor, which I can’t - if I understood it right - since the whole game data (except for the UI) is found in the dll.
No, my game is not like Starcraft. This will be a city and you can click on each area in the grid and modify it. Hence, I don’t think a dead background would be a good idea, but for now I’m happy if I can see anything at all
Thank you very much. I think jc-drile77’s links got me moving. Terms are tricky. You know what you want to do but you have no terms for it so you search in the wrong place. Thank you kindly for your help, all of you.