Touch to Mouse Input Converter for PlayMaker on Unity 3D #unity3d #gamedev

Media_httpblobsgett57_icgqq

If you are using PlayMaker plugin for Unity3D and are struggling with touch input in your game built with mouse events, I made a FSM to convert touch input into mouse input in my project so that it will work on my Mac and iPhone at the same time. Just drop the prefab into your scene, or create a GameObject, add FSM, and paste the template in the .asset file.

Download link: http://ge.tt/57U7eII

Basically, when a user touches the screen (Touch Began), this FSM will send a MOUSE DOWN event to the object touched, and send a MOUSE UP event to the object touched when the user lifts his/her finger (Touch Ended).

Posted via email from Next Level with Brandon


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

Reference: How to fix “Base SDK missing” after updating to Xcode 3.2.3/3.2.5

Overview

I’m going to explain why this is going on, and then how fix the specific “Base SDK Missing” problem. You can skip to the bottom for just the fix, though I recommend reading all of this. I also recommend John Muchow’s excellent take on this issue.

If you are specifically interested in the Xcode 3.2.4 upgrade, which has a strongly related problem, you might want to confer here.

One SDK to rule them all

Here’s the deal: 4.0 is now the only SDK version allowed for submitting new or updated iPhone-only apps. This is direct from Apple’s iOS 4 Readiness Checklist (reg reqd):

All new applications and updates to existing applications must be built with iPhone SDK 4. Please note, the App Store will no longer support applications that target iOS 2.x.

Presumably — I’m guessing here — iPad-only and universal apps should use the 3.2 SDK. That is why 4.0 & 3.2 are your only choices for SDKs.

That is also why your project is now broken, since the SDK it was previously mapped to is deprecated, gones-ville.

(But) 3 is a magic number

Relax. You can still target devices running iPhone OS 3.0 (but not lower). The SDK you use to compile does not limit — downward — what iOS version you can program to or support. Once you’ve patched things up in your project etc. (cf. next section) you can set “iPhone OS Deployment Target” to a lower iOS version. For a quick shot of how to do this, cf. step 7 in the next section.

Note that you are now entering some tricky terrain. Your usual Xcode 3.2.3 compiler will no longer be enforcing your compliance to 3.0-only calls, nor does it have a simulator for these. And if you want to support 4.0 features, you’ll have to do some conditional code to prevent crashes on 3.0 devices. Fun.

You can still download (from Apple!) and install a previous Xcode version or SDK (cf. here). Yes, you can install multiple Xcode versions, in different directories, i.e. put only one version in /Developer. You can use the old Xcode to test your app’s compliance vs. a 3.x SDK, moving the hard work to a fancy compiler, and simulator. But you can no longer use the products of the previous SDKs to submit to the app store.

FWIW, I plan on doing just this check before I ship.

What condition my condition is in

Matt Gallagher has a Cocoa with Love post on version conditional code entitled “Tips & Tricks for conditional iOS3, iOS3.2 and iOS4 code”. If you are planning on conditionally using 4.0 features, this is a strong recommendation to check it out.

Fixing “Base SDK Missing”

  1. Load your project
  2. From the menu, select Project > Edit Project Settings…
  3. Under Architecture > Base SDK, choose one of the available device options: iPhone 3.2 or iPhone 4.0. If you are iPhone-only, 4.0 is the way to go.
  4. Close that window.
  5. From the menu, select Project > Edit Active Target “YourTarget”
  6. Under Architecture > Base SDK, choose one of the available device or simulator options: iPhone 3.2 or iPhone 4.0.
  7. If you want to target previous iOS versions, then in that same window, under Deployment > iPhone OS Deployment Target, select the lowest version you want to support. Note that support for 2.x versions through the app store is deprecated. See the “Readiness Checklist” quote above.

Addendum

More detailed information on this topic can also be found in the first answer to this question. There’s also some useful info here.

Posted via email from Next Level with Brandon


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

FWD: col000r: Unity: Have scripts run while the game doesn’t

Unity: Have scripts run while the game doesn’t

There’s a way to force scripts to run even if the game is not running in the Editor:

In Javascript, simply put this on the top of the script:

@script ExecuteInEditMode()

And for C#:

[ExecuteInEditMode()]

Thanks to @col000r for this tip! Source: http://col000r.blogspot.com/2010/08/unity-have-scripts-run-while-game.html

Posted via email from Next Level with Brandon


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

Reference: switching ON/OFF a C# script with a javascript script during runtime. #unity3D

make sure you’ve put the files in the right places per this document:
http://unity3d.com/support/documenta…dvanced29.html

Next, try this code. It works with both scripts are components on the same object:

C#:

Code:
using UnityEngine;
using System.Collections;

public class FrameCounter : MonoBehaviour {

	public int frameCount = 0;

	// Update is called once per frame
	void Update () {
		if ( (++frameCount % 100) == 0) {
			Debug.Log( "frameCounter = " + frameCount );
		}
	}

}

UnityScript:

Code:
function Update () {
	if ( Input.GetKeyDown( KeyCode.S ) ) {
	   var fc : FrameCounter;
	   fc = gameObject.GetComponent("FrameCounter");
       fc.enabled = false;
    }
}




Posted via email from Next Level with Brandon



Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

For Unity3D Stats Junkies – Web Player Hardware Statistics

If your Unity 3D game is going to be mainly played on the browser, you should pay attention to this data on user hardware.

from http://unity3d.com/webplayer/hardware-stats

found via @mrchrisallen

 


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

Unity3D Beginners Tip Of The Day: Dealing with Error “BCE0018: The name… does not denote a valid type.”

I ran into this problem when I tried to access a function in a class/script that I’ve downloaded from the wiki from another script that I wrote. I kept getting this BCE0018 error telling me “The name (class name) does not denote a valid type”. It took me a while to find out that it is because the script I downloaded was written in C#, and the script I wrote was in Javascript – and due to the way scripts are compiled in Unity3D, I need to have the C# script in “Standard Assets” folder and the Javascript outside of that folder for it to work. Read more on this page Script Compilation

 

All scripts that are compiled in this step have access to all scripts in the first group (“Standard Assets”, “Pro Standard Assets” or “Plugins”). This allows you to let different scripting languages interoperate. For example, if you want to create a Javascript that uses a C# script: place the C# script in the “Standard Assets” folder and the Javascript outside of the “Standard Assets” folder. The Javascript can now reference the C# script directly.

 

 

 


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

Unity3D for Beginners: Adding Shadow / Outline, and Changing Font Size / Color on the Text #Unity3D

 

After toying with a few different methods of creating in-game text, I decided to use guiText for it’s simplicity and for all the GUI scripts you can use from Unity Wiki

 

Unity 3D does not have a visual GUI editor at the moment, so it isn’t always obvious how to do simple things like changing the font and adjusting font size. Here’s a quick note of how to get these basics done to get you started with in-game text!

 

1. How do I change the font size for the text for guiText objects? 

 

Go to Project view and find the font you are using. There you can find the setting for font size in the “import setting”. If you are using Unity iPhone, right click on the font to find “import setting”. If you need multiple font sizes, you can duplicate the font and have different import setting on each.  

 

 

Alternatively you can disable “Pixel Correct” on the GUIText object itself and adjust the scale. However the text might get blurry this way so I don’t recommend it. 

 

 

 

2. How do I change the color of the text for guiText objects?

 

You change the color of the text by changing the color of its “material”. You can find the option in the Project view with your Font. 

 

 

However if you change this color here, it will apply to all the GUIText object with this font. What if you want different GUIText objects to have different colors? I created a short script that can be attached to the GUIText object to change the color at run time. You can attach this script on your GUIText objects and select the color you want in the Inspector view when you select the GUIText object. 

 

 

The script is simple, see below:
//this script changes the guiText color of the object and should be attached to an guiText object
//from http://www.plinan.com
var TextColor : Color = Color.white; // define the color for this guiText object
function Start () {
     guiText.material.color = TextColor; 
}
3. How do I add an outline or shadow to my text with guiText?

 

This is a bit more complicated. I use two methods in the game to create shadows and both require a little bit of work. 

 

The first method is to create a duplicate of the same guiText (with the same text but a darker color) and move it 1 pixel to the right and 1 pixel to the bottom of the original guiText object to create a shadow effect. Make sure the duplicate is behind the original object. (You can change the renderQueue (more info) of your objects to make sure the original is in front of the duplicate. ) If you want to create a border instead of a shadow around the text, use the same method, create two duplicates, and place them behind the original slightly offset to create a border.

 

This is what it looks like. 

 

This is a simple solution. However it has its problems. I need a way to display moving text, and the text doesn’t look very good with this method as the two objects don’t always move at the exact same time. So I had to find another way to create shadows for the text. 

 

Fortunately Unity Wiki provided a solution to do this with these two scripts: SaveFontTexture and TexturedFont

 

The basic idea is to 
1. Export the Font Texture
2. Edit the Texture so that it has your desired effects (outline, shadow, or any other effects) with Photoshop or Gimp
3. Create a Material with the new Texture you’ve created
4. Use the Material together with the TexturedFont shader on the guiText object.

 

Here’s the instruction from the wiki:

Description

If you’ve ever wanted to get at the auto-generated font bitmap that Unity creates when importing vector fonts, now’s your chance. SaveFontTexture saves that bitmap as a .png file so you can edit it, add whatever whizbang effects you want to it, and then use it as a colored font, using the TexturedFont shader and a GUIText object.

Script Setup

You must place the script in a folder named Editor in your project’s Assets folder for it to work properly. When this is done, you will then have a Save Font Texture menu item in the Assets menu. Find the TrueType font you want in Unity and open the root, which reveals the auto-generated material and texture. Click once on the texture (called “font Texture”) and select the Save Font Texture menu item. Choose a file name and location in the file dialog, and hit save. (Technically this script will work for any texture in Alpha8 format, if for some reason you wanted to save it as a .png file.)

Customizing and Using Font Textures

1. Get the TrueType font that you want to modify in Unity at the desired Font Size (so that you can use Pixel Correct in the GUI_Text object that will use it for crisp rendering).

2. Use this script (installed as described above) to save the texture Unity generates automatically for the font.

3. Edit that texture file in Photoshop to use in your project.

4. Create a new Material in Unity.

5. Set the texture of the material to the modified texture.

6. Set the shader of the material to the TexturedFont Shader.

7. In any scene GUI_Text objects that will use the custom font, apply the original font to the object then change its material to the custom material created in steps 4-6. 

 

Again, it looks like this in my game. I applied a small shadow to the text so it’s hard to see but it looks very different from text without the shadow. 
Without shadow: 
With shadow: 
It helps to make the text more readable. 
By the way, if you are looking for fonts to use, I found a few at MyFont.com. They also have free fonts that can be used for commercial purposes. 
I think that’s all I have to say about guiText for now. Cheers!


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

Unity Beginner Tip of the Day: Rigidbody Required for Collision/Trigger Events #Unity3D

“If you are moving a GameObject through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.”


From unity3d.com – Unity Reference Document: Rigidbody

This might seem obvious. The rigidbody component is used when you want your game object to have physics applied on it. Unity has Ageia (now part of Nvidia) physX engine built-in, so you can easily make a game with physics in it – stuff like gravity, realistic collisions, forces, and torque. It can create some very impressive and natural-looking effect. (similar to Little Big Planet or this Unity-powered gem Cordy)

But what if you don’t want the fancy physics? You can simply remove the rigidbody component in your game. However if you have any collision or trigger messages in your game, that is, if you use any OnCollision or OnTrigger functions, they will no longer work. As stated at the bottom on the Rigidbody reference page, “If you are moving a GameObject through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.”

So the bottom line is, if you don’t want to use physics for the objects in your game but need to have collisions and triggering events, keep the rigidbody component on the objects and Enable “Is Kinematic” – which disabled the object from having physics applied to it.

Posted via email from Brandon Wu’s Road to Where He Wants to Be



Got an amazing game idea? See how we can build it for you at Studio Pepwuper.

Unity3D for Beginners: Creating the Visual for the Line of Sight / Vision Cone / Field of View

 

 

I put off creating a visual representation for the line of sight for the NPCs in the game for quite some time. It just seemed very complicated, especially after various forum posts I’ve read where everyone has different opinions about the best way to create a line in Unity3D. A lot of people also are trying to figure out how to create a line of sight (aka a vision cone, field of view) Messing with raycast seemed like a headache to me however. Anyhow, some of the options I found were:

 

1. Line Renderer: This is the built-in class in Unity3D. You create a game object and attach this to it. Done. The script reference is here

 

2. Vector Line: From Unity Wiki. “Draws a vector line on the screen based on normalized viewport coordinates.” I didn’t get to try it as I don’t have Unity Pro yet. 

 

3. Vectrosity ($): This commercial plug-in is quite powerful and the interaction between the vector graphics and the 3D world is very impressive. Also quite reasonably priced in my opinion ($7, $25). 

 

4. Dynamically drawing on the ray: This just seemed too complicated for my simple need in the game. 

 

 

 

In the end, I decided to use a simple solution to create a Line Renderer object and tweak the starting and ending sizes to make it look somewhat like a cone. I created an image of a dotted line for the Line Renderer material. And I attached the Line Renderer object to the NPC object and have it drawn in the Z-axis(which is the direction the NPC is facing) by 2 units. See the image below for how I set up the Line Renderer object in the inspector. (Please ignore the transform as it’s related to how my NPCs are constructed.)

 

 

 

And that’s all! Please note that this only creates the visual of the line of sight but does not actually create a line of sight for the NPC to detect players. I will write another post on how I did that in a separate post. 

 

Best,
Brandon Wu

 

Blog: http://www.plinan.com
Linkedin Profile: http://www.linkedin.com/in/wubrandon

Posted via email from Brandon Wu’s Road to Where He Wants to Be


Got an amazing game idea? See how we can build it for you at Studio Pepwuper.