Hello,
I am new to C# and Javascript (Unity overall to be honest) and I am trying to connect Javascript with C# and the connection has been established however I have a problem in retrieving a variable from the script.
I want to receive surfaceIndex from TerrainLocalisation in the OSCcontrol but I cannot retreive the integer to compare it against other integers.
Error type: error CS0119: Expression denotes a method group', where a
variable’, value' or
type’ was expected
TerrainLocalisation.js below (localised in Standard assets)
#pragma strict
var surfaceIndex : int = 0;
private var terrain : Terrain;
private var terrainData : TerrainData;
private var terrainPos : Vector3;
function Start()
{
terrain = Terrain.activeTerrain;
terrainData = terrain.terrainData;
terrainPos = terrain.transform.position;
}
function Update()
{
surfaceIndex = GetMainTexture( transform.position );
}
public function TextureReturn(surfaceIndex)
{
return surfaceIndex;
}
// - just for GUI demonstration -
function OnGUI()
{
GUI.Box( Rect( 10, 10, 25, 25 ), surfaceIndex.ToString() );
}
// ----
function GetTextureMix( worldPos : Vector3 ) : float[]
{
// returns an array containing the relative mix of textures
// on the main terrain at this world position.
// The number of values in the array will equal the number
// of textures added to the terrain.
// calculate which splat map cell the worldPos falls within (ignoring y)
var mapX : int = parseInt( ((worldPos.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth );
var mapZ : int = parseInt( ((worldPos.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight );
// get the splat data for this cell as a 1x1xN 3d array (where N = number of textures)
var splatmapData : float[,,] = terrainData.GetAlphamaps( mapX, mapZ, 1, 1 );
// extract the 3D array data to a 1D array:
var cellMix : float[] = new float[ splatmapData.GetUpperBound(2) + 1 ];
for ( var n : int = 0; n < cellMix.Length; n ++ )
{
cellMix[n] = splatmapData[ 0, 0, n ];
}
return cellMix;
}
function GetMainTexture( worldPos : Vector3 ) : int
{
// returns the zero-based index of the most dominant texture
// on the main terrain at this world position.
var mix : float[] = GetTextureMix( worldPos );
var maxMix : float = 0;
var maxIndex : int = 0;
// loop through each mix value and find the maximum
for ( var n : int = 0; n < mix.Length; n ++ )
{
if ( mix[n] > maxMix )
{
maxIndex = n;
maxMix = mix[n];
}
}
return maxIndex;
}
// ----
And OSCControl.cs below:
using UnityEngine;
using System.Collections;
using LibPDBinding;
using System;
using System.Runtime.InteropServices;
public class OSCControl : MonoBehaviour
{
private GCHandle dataHandle;
private IntPtr dataPtr;
public string patch;
private int patchName;
private bool islibpdready;
private string path;
public bool playOnAwake = false;
float t = 0.0f;
public bool patchIsStereo = false;
private TerrainLocalisation goScript;
private int TerrainIndex;
void Awake ()
{
path = Application.dataPath + "/Resources/" + patch;
if ( playOnAwake)loadPatch ();
}
void Start ()
{
goScript = (TerrainLocalisation) gameObject.GetComponent("TerrainLocalisation");
}
void Update()
{
t = Time.deltaTime;
TerrainIndex = goScript.TextureReturn();
if (TerrainIndex == 0) {
} else {
if (TerrainIndex == 2) {
}
else {
if (TerrainIndex == 3) {
}
else{
if (TerrainIndex == 4) {
}
else {
return;
}
}
}
}
}
public void loadPatch ()
{
if(!islibpdready)
{
if (!patchIsStereo) LibPD.OpenAudio (1,1, 48000);
else LibPD.OpenAudio(2,2,48000);
}
patchName = LibPD.OpenPatch (path);
LibPD.ComputeAudio (true);
islibpdready = true;
}
public void OnAudioFilterRead (float[] data, int channels)
{
if(dataPtr == IntPtr.Zero)
{
dataHandle = GCHandle.Alloc(data,GCHandleType.Pinned);
dataPtr = dataHandle.AddrOfPinnedObject();
}
if (LibPD.Process(32, dataPtr, dataPtr)==0) {
}else Debug.Log("End");
}
void OnGUI()
{
}
// delegate for [print]
void Receive(string msg)
{
Debug.Log("print:" + msg);
}
public void closePatch ()
{
//LibPD.Print -= Receive;
LibPD.ClosePatch (patchName);
LibPD.Release ();
}
void OnApplicationQuit ()
{
Debug.Log("On Quit");
closePatch ();
}
public void OnDestroy()
{
Debug.Log("On Destroy");
dataHandle.Free();
dataPtr = IntPtr.Zero;
}
}