Vector2 c# defining

Hi,

I’m building a concept game for my bachelor assessments to get accepted into my dream school. Following a javascript tutorial on how to make tools, I as a noob in c# programming told myself i will converse javascript(language i also don’t know) into c#.

Now i have to following code in c#

using UnityEngine;
using System.Collections;

public class Step3 : MonoBehaviour
{
		public int tileX = 1;
		public int tileY = 1;

		void Update ()
		{
				renderer.material.mainTextureOffset = new Vector2 (0.25F, 0);
				
				Vector2 size = new Vector2 (1.0 / tileX, 1.0 / tileY);
				
				renderer.material.mainTextureScale = size;
				Debug.Log (size);
		}
}

I translated this from the following javascript code:

var tileX : int;
var tileY : int;

function Update ()
{
	renderer.material.mainTextureOffset = Vector2 (0.25, 0);

	var size = Vector2 (1.0 / tileX, 1.0 / tileY);
	renderer.material.mainTextureScale = size;
	print(size);
}

Can someone tell me and explain what the hell I’m doing wrong?

Thanks in advance.

Jan

The only thing I see wrong is this line:

var size = Vector2 (1.0 / tileX, 1.0 / tileY);

You need to add the ‘F’ on floating point values:

var size = Vector2 (1.0F / tileX, 1.0F / tileY);

For future questions, it is very helpful for you to include a description of what problem you are having…runtime or compile time and a copy of any error message.

Well the problem is: I am using c# code(the above piece of code) the tutorial maker uses javascript (the code below).

The variable you gave me is the javascript version… and I need the C# version.

When I copy paste your code in place with my code it gives me this error:

Assets/Scripts C#/Step4.cs(14,28): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

Assets/Scripts C#/Step4.cs(15,51): error CS0266: Cannot implicitly convert type `object' to `UnityEngine.Vector2'. An explicit conversion exists (are you missing a cast?)

What should i do? I tried making it :

Vector2 size = new Vector2 (1.0F / tileX, 1.0F / tileY);

But that doesn’t work.

Btw Thank you for the quick reply!!

Oh wait,

That last code does work:O
Thank you for pointing out the F for me.

May i ask what the difference is between the lower f and the capital F ?

Thanks in advance

Sorry I am really new to using the unity forums. Actually this was my first topic:O
Thank you for the advice, the code is working now:)

I guess i will have to look up the difference and start learning more about the language.