public Sprite tile_plain; // assign this in unity by dragging a sprite to it
void Start()
{
GameObject tile = new GameObject();
tile.AddComponent();
tile.GetComponent().sprite = tile_plain;
tile.transform.position = new Vector2((i * tile_plain.rect.width)/tile_plain.pixelsPerUnit, 5f);
}
Thursday, January 29, 2015
Unity2D script to programatcally add a sprite
I'm create a grid of tiles. The tiles are sprites and I'm laying them out programmatically. Here is the code to generate one of the tiles.
Wednesday, January 28, 2015
Unity2D Screen size
Still messing with Unity 2D and wanted to make a note on now to find the screen size and the upper left coordinate. This will be something I need for every game.
using UnityEngine; using System.Collections; public class ScreenSize : MonoBehaviour { void Start() { float ScreenHeight = Camera.main.orthographicSize*2; float SceenWidth = Camera.main.aspect * camHalfHeight; // Set a new vector to the top left of the scene Vector3 topLeftPosition = new Vector3(-ScreenWidth/2, ScreenHeight/2, 0) + Camera.main.transform.position; } }
Tuesday, January 27, 2015
Unity 2D Units
I'm building a tile system to display a grid of sprits in my game. I'm old school and used to just using pixels so a 32 pixel wide sprite is 32 pixels wide.
so when I do this to create a strip of sprites
Then only one sprite element shows up on the screen and the others, while they are there are off the screen. To do this, you have to divide by the pixels per unit identified in the sprite.
(a public method variable)public Sprite tile_plain;
int i;
for (i=0;i<25;i++)
{
GameObject tile = new GameObject();
tile.AddComponent();
tile.GetComponent().sprite = tile_plain;
tile.transform.position = new Vector2((i * tile_plain.rect.width), 5f);
Then only one sprite element shows up on the screen and the others, while they are there are off the screen. To do this, you have to divide by the pixels per unit identified in the sprite.
(a public method variable)public Sprite tile_plain;
int i;
for (i=0;i<25;i++)
{
GameObject tile = new GameObject();
tile.AddComponent();
tile.GetComponent().sprite = tile_plain;
tile.transform.position = new Vector2((i * tile_plain.rect.width)/tile_plain.pixelsPerUnit, 5f);
This was a good Stackoverflow post (Unity 4.3 - understanding positions and screen resolution, how to properly set position of object?) on the topic.
Monday, January 26, 2015
Surface Pro 3 and Visual Studio network conflict
I've recently been using a surface pro 3 for my development. I love it as it works great on planes and when I travel. I had been having one issue with the network on sleep, it never returned and I had to continually reset it. I also found that sleep had been replaced by hibernate and it took 20 seconds to come back to life every time I left it alone for a few minutes. It turned out that Visual Studio 2013 installs Hyper-V.
This was a great explanation of the problem.
http://winsupersite.com/mobile-devices/surface-pro-3-tip-hyper-v-vs-connected-standby
I don't plan on using Hyper-V so I can turn it off. Basically I just ran a command prompt as administrator and used this command.
bcdedit /set hypervisorlaunchtype off
as this blog is mostly for my own note taking purposes, I'm going to return here if I need to run it again or I need to turn it back on
Here is how I'm going to turn it back on.
bcdedit /set hypervisorlaunchtype auto
This was a great explanation of the problem.
http://winsupersite.com/mobile-devices/surface-pro-3-tip-hyper-v-vs-connected-standby
I don't plan on using Hyper-V so I can turn it off. Basically I just ran a command prompt as administrator and used this command.
bcdedit /set hypervisorlaunchtype off
as this blog is mostly for my own note taking purposes, I'm going to return here if I need to run it again or I need to turn it back on
Here is how I'm going to turn it back on.
bcdedit /set hypervisorlaunchtype auto
Labels:
fails on restart,
hibernate,
hyper-v,
issue,
network,
not working,
sleep,
surface pro 3,
surface_pro
Friday, January 23, 2015
Kids name printing
I now it's not software development, but my three toddlers are learning how to write and I found this really cool name tracing site.
Thursday, January 22, 2015
Board games for programmers
If you have a group of programmers, RoboRally is a really really fund game. You create little five card instructuctions for your robot and send him off. Invariably, people put in bugs or run into other robots and cause hilarious effects. I've played this many times with developer teams and everyone has fun.
Wednesday, January 21, 2015
Theory of fun
I've been revisiting this book on game design and really enjoying it. It will really help you understand what makes fun games fun.
Also, this book does a good job of talking about violence in video games and what it actually means. I don't know if it was in the book or not, but I remember reading this and coming up with a defense of violence in video games. Not that I condone violence, I like peaceful people, but the fact is that you can only complain about game violence if you've never played this children's classic.
.
.
Tuesday, January 20, 2015
How to configure a Unity project to use VisualStudio
I started a new 2D project to try and see if I could port an old game I did in Java called EmPathMe (http://www.woodsgoods.com/gaw, Good luck getting it to run).
When I went to launch a script in VisualStudio it complained there wasn't a .sln file so I had to figure it out again. I'm leaving myself this post so I don't have to figure it out again.
You select Assets/Import Package/Custom Package...
When I went to launch a script in VisualStudio it complained there wasn't a .sln file so I had to figure it out again. I'm leaving myself this post so I don't have to figure it out again.
You select Assets/Import Package/Custom Package...
Then you navigate to the location where the VisualStudio Tools for Unity were installed (http://unityvs.com/). I installed them in the default location C:\Program Files (x86)\Microsoft Visual Studio Tools for Unity\2013. The debug only works well with VisualStudioPro and I have no idea how I'm going to pay for the pro version once my That's one reason I'm setting this up so I can get the touch code working well before my trial license expires
Choose all the package assets.
Now you will have the Visual Studio Tools menu and you can generate the project files so you don't see the error about not having a .sln file when launching the Unity editor.
Monday, January 19, 2015
Unity 2D Tutorials
These tutorials on the new Unity 2D features have been very helpful.
http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-overview
http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-overview
Thursday, January 15, 2015
Bing rewards
I've recently switched to Bing as my search engine. I tried it because they have a rewards program and after a few months I really don't see any difference.
Try Bing rewards, it makes search just a little more fun.
Bing rewards is running a 1,000,000 reward points give away. Sign up here.
Try Bing rewards, it makes search just a little more fun.
Bing rewards is running a 1,000,000 reward points give away. Sign up here.
Wednesday, January 14, 2015
Unity script referencing
I wanted my keyboard input script to retrieve a value from a grid generator script so it knew how far to move one of my game objects. It took me a while to figure it out even though it's simple so I figure it's best to leave myself a bread crumb so I don't have to search so much next time.
//this is how you get a reference and value out of another script
scriptholder = GameObject.Find("EmptyScriptHolder");
GridManager script = scriptholder.GetComponent<GridManager>();
print("Grid gap =" + script.stepsize);
This shows how to get a reference to the actual script, in this case it's my EmptyObject I use to hold scripts that are not associated with actual GameObjects. I call it EmptyScriptHolder. I then get the reference to the GridManager script. This is the actual type name of the script. Within that script is a method variable called stepsize. Overall it's very simple to get a value out of another script once you know how to do it.
This site was very helpful even though it's documentation from a few versions back.
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Tuesday, January 13, 2015
Hexagon grids
I'm not building a game that uses a hexagond grid right now, but have done it before and thinking about what it takes and found this great hexagon algorithm resource.
Subscribe to:
Posts (Atom)