Archive for the 'Unity3D' Category
Three things to remember…
For adding to iPhone speed:
1. #pragma strict
2. Script Call Optimization
A good development practice on the iPhone is to never rely on exception handling (either internally or through the use of try/catch blocks). When using the default Slow and Safe option, any exceptions that occur on the device will be caught and a stack trace will be provided. When using the Fast but no Exceptions option, any exceptions that occur will crash the game, and no stack trace will be provided. However, the game will run faster since the processor is not diverting power to handle exceptions. When releasing your game to the world, it’s best to publish with the Fast but no Exceptions option.
3. Stripping Level
Most games don’t use all necessary dlls. With this option, you can strip out unused parts to reduce the size of the built player on the iPhone. If your game is using classes that would normally be stripped out by the option you currently have selected, you’ll be presented with a Debug message when you make a build.
Keeping those Draw Calls down…
Diffuse shader that doesn’t need a light:
Shader "Texture Simple" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white"
}
SubShader {
Pass {
SetTexture [_MainTex]
}
}
}
Transparent Diffuse shader that doesn’t need a light:
Shader "Texture Simple Transparent" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
Category {
//ZWrite Off
Alphatest Greater 0
Tags {Queue=Transparent}
Blend SrcAlpha OneMinusSrcAlpha
SubShader {
Pass {
Lighting Off
SetTexture [_MainTex]
{
constantColor [_Color]
Combine texture * constant, texture * constant
}
}
}
}
}
UV Animations in Unity iPhone
var tileSize : Vector2;
var columns : float = 6;
var rows : float = 7;
var startPosition : Vector2;
var framesPerSecond : float = 41;
function Start (){
tileSize=Vector2(1/columns,1/rows);
startPosition=Vector2(0,tileSize.y*(rows-1));
renderer.material.mainTextureOffset = startPosition;
renderer.material.mainTextureScale=Vector2(1/columns,1/rows);
}
function Update(){
var index : int = Time.time * framesPerSecond;
var offset : Vector2 = Vector2(tileSize.x*(index%columns),startPosition.y-(Mathf.Floor((index/columns)%rows)*tileSize.y));
renderer.material.mainTextureOffset = offset;
}
Smoothing out iPhone’s accelerometers
Short. Simple. Works.
var steering:float;
function Update () {
steering = Mathf.Round(Mathf.Lerp(steering, iPhoneInput.acceleration.y*10, Time.time));
}
iPhone easy button handling
Easiest method I could come up with for easy GUITexture as button work:
static var braking : boolean;
function Update () {
for(touch in iPhoneInput.touches){
if(touch.phase == iPhoneTouchPhase.Began){
if (guiTexture.GetScreenRect().Contains(touch.position)){
guiTexture.color=Color(.2,.2,.2,.5);
braking = true;
}
}
if(touch.phase == iPhoneTouchPhase.Ended){
guiTexture.color=Color(.5,.5,.5,.5);
braking = false;
}
}
}