- Home /
Question by
joseaguirre · Mar 14, 2013 at 12:20 AM ·
javascriptinputcontrollerchangesupport
Unity Controller Support Help
Hello Fellow friends and Unity peers!
I have a simple question for you guys.....
I have this script that uses the arrow keys instead of the Horizontal Input....
#pragma strict
var artex : Texture[];
var uvAnimationTileX = 1; //Here you can place the number of columns of your sheet.
//The above sheet has 24
var uvAnimationTileY = 6; //Here you can place the number of rows of your sheet.
//The above sheet has 1
var framesPerSecond = 10.0;
private var iTexture = 1;
private var iNewTexture = 0;
function Update () {
if (artex.Length < 3) {
Debug.Log("Need to assign textures in the inspector");
return;
}
if (Input.GetKey(KeyCode.LeftArrow)) {
iNewTexture = 0;
uvAnimationTileX = 3;
uvAnimationTileY = 1;
}
else if (Input.GetKey(KeyCode.RightArrow)) {
iNewTexture = 2;
uvAnimationTileX = 3;
uvAnimationTileY = 1;
}
else {
iNewTexture = 1;
uvAnimationTileX = 1;
uvAnimationTileY = 6;
}
if (iNewTexture != iTexture) {
iTexture = iNewTexture;
renderer.material.mainTexture = artex[iTexture];
}
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
The xbox controller moves my player but this script does not work on it.... i need this script to use the Horizontal input instead of the arrow keys
screenshotunity.png
(143.3 kB)
Comment