Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jul 17, 2014 at 04:23 PM by Graham-Dunnett for the following reason:

Duplicate Question - http://answers.unity3d.com/questions/topics/cs0119.html

avatar image
0
Question by graceinspace · Jul 17, 2014 at 01:07 PM · javascriptcs0119

Javascript communication to C#, Error CS0119, method group vs variable

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;
     }
     
 }
 





Comment
Comments Locked
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0

Answer by Landern · Jul 17, 2014 at 01:12 PM

in OSCControl.cs, you have not declared t as a float:

 float t = Time.deltaTime; // <-- line 13

in line 14 you try and call a function/method called surfaceIndex, that is incorrect. The method that you created in the unity script file (function TextureReturn(surfaceIndex)) is being invoked incorrect. The method would look more like:

 goScript.TextureReturn(someValueThatIsTheSurfaceIndex);

and that would return in this particular case that value from that parameter for the function... Thought i'm sure you're just testing things.

You also didn't declare TerrainIndex in that same file, it appears to be of int type:

 int TerrainIndex = goScript.TextureReturn();

if in these calls you wanted to just return the field you defined as:

 var surfaceIndex : int = 0;

in your unityscript file, you would get the component as you did and:

 int index = goScript.surfaceIndex;

Note: you can use type inference in c#, but that appears to be a little advanced for this.

Comment
Comments Locked · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image graceinspace · Jul 17, 2014 at 01:45 PM 0
Share

Hello!

Thanks for your help, however with my beginners brain I am struggling to understand everything you have wrote.

I did declare t as a float but its not relevant to the problem thus I did not copy this in. There are other methods that alter the surfaceIndex and I just want to receive the value of it in my cs script and compare against it.

Would you know how to deal with this?

I would greately appreciate your help!

avatar image Landern · Jul 17, 2014 at 01:48 PM 0
Share

@graceinspace, so you posted incomplete code, fantastic, you do realize that %99.9 of use post to help and we get nothing out of this.

Again, i explained how you can pull the value through the function/method and through the field you declared in the unityscript(javascript) file. If your code doesn't reflect what you're using... i'll see myself out.

avatar image graceinspace · Jul 17, 2014 at 01:52 PM 0
Share

I am really sorry! It is my first post and I apologise deeply about this! I should have done that in the first place..

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Physics.OverlapSphere with a min radius? 1 Answer

Door Opens Automatically, then it stays open forever. How? 2 Answers

Have an Int be in a Network Noob Networking Question 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges