Passing textureCoords to a function

Hi there

Why am I getting troubles with the following script structure - I am getting “Cannot convert ‘void’ to ‘void’.”

function Update()
{
var texa = texturea.textureCoord;
var texb = textureb.textureCoord;

var returnval = newtext(texa, texb);
}

function newtext(ta, tb)
{
var texta = ta;
var textb = tb;

};

and also when I try

Debug.Log(texa , texb) I get error yet is I have:

Debug.Log(texa) it returns a Vector2 which is great!!

I am obviously having trouble understanding data types and how to pass them around?

In your second function:

function newtext(ta, tb) 
{
   var texta = ta; 
   var textb = tb; 
};

the types for both the arguments and the local variables are undeclared. Try explicitly declaring the type of either one of those, such as:

function newtext(ta : Vector2, tb : Vector2) 
{
   var texta = ta; 
   var textb = tb; 
};

Also, if you call Debug.Log with two arguments, the second one needs to be an Object that Unity can draw a connection to in the Editor, which probably means something in the Hierarchy or Project views.

When programming Javascript for Unity, I have a very precise format which avoids a lot of errors. Here’s an example:

function MyFunction (variable1 : int, variable2 : int[]) : int
  {
    var otherVariable : int = 5; 
    return otherVariable;
  }

code similar to the above will keep you from getting those errors you are receiving.

I really recommend always choosing a type.