Hi, I was wondering if someone can please convert the following files into C#. I have tried to do this but am getting errors. Thanks
File 1:
using UnityEngine;
using System.Collections;
public class Texture_Tile_Animation : MonoBehaviour
{
public int uvAnimationTileX = 4;
public int uvAnimationTileY = 4;
public float framesPerSecond = 10.0F;
private float index;
private Vector2 size;
private Vector2 offset;
private float uIndex;
private float vIndex;
void Start()
{
StartCoroutine(DoTiling());
}
IEnumerator DoTiling()
{
while(true)
{
// Calculate index
index = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
size = new Vector2 ( 1.0f / uvAnimationTileX, 1.0f / uvAnimationTileY );
// split into horizontal and vertical index
uIndex = index % uvAnimationTileX;
vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
offset = new Vector2 ( uIndex * size.x, 1.0f - size.y - vIndex * size.y );
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
yield return new WaitForEndOfFrame();
}
}
}
Errors are:
Assets/_Scripts/_Tile_UV_Animation/Texture_Tile_Animation.cs(34,90): error CS1502: The best overloaded method match for `UnityEngine.Vector2.Vector2(float, float)’ has some invalid arguments
Assets/_Scripts/_Tile_UV_Animation/Texture_Tile_Animation.cs(34,90): error CS1503: Argument #1' cannot convert
double’ expression to type `float’
//----------
Original JavaScript file:
#pragma strict
var uvAnimationTileX : int = 4;
var uvAnimationTileY : int = 4;
var framesPerSecond : float = 10.0;
private var index : int;
private var size : Vector2;
private var offset : Vector2;
private var uIndex : float;
private var vIndex : float;
function Start() {
DoTiling();
}
function DoTiling() {
while(true) {
// Calculate index
index = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
uIndex = index % uvAnimationTileX;
vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
yield WaitForEndOfFrame();
}
}