Search Unity

Translate JavaScript in C#

Discussion in 'Scripting' started by Giannigiardinelli, Dec 15, 2014.

  1. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Hello everyone,

    I would like to manage to translate this Javascript of the tutoriel design3 into C#
    I do not know if is well to mix its plays with scripts different i.e., java and C#? If that is not a problem I would not need to translate it?
    But apparently it is to advise to make its play in c# if somebody can confirm it to me?
    Good I make some publish this post to help me to translate this script which is in java, I am to manage there to badly translate not thing except the list “Array” which apparently this finds that on java, therefore if somebody can help me to translate that I would be recognize to him!


    JavaScript :
    Code (csharp):
    1.  
    2.  
    3.  
    4. private var posBags : Vector2[];
    5. private var flagAvailable : Array;
    6. private var indexBags : int;
    7. private var toggleAllBags : boolean = false;
    8.  
    9. private var objectsInBag : GameObject[];
    10.  
    11. function Start(){
    12.  
    13.     objectsInBag = new GameObject[64];
    14.     flagAvailable = new Array();
    15.  
    16.     posBags = [Vector2(195,260), Vector2(195,465), Vector2(385,260), Vector2(385,465)];
    17.     for( var i = 0; i < posBags.length; i++){
    18.         flagAvailable.Push(true);
    19.     }
    20.     indexBags = 0;
    21. }
    22.  
    23. function Update(){
    24.  
    25.  
    26. }
    27.  
    28. function GetPositionAvailable(){
    29.     var found : boolean = false;
    30.     for(indexBags = 0; indexBags < flagAvailable.length; indexBags++){
    31.         if(flagAvailable[indexBags]){
    32.             found = true;
    33.             break;
    34.         }
    35.     }
    36.     if(!found){
    37.         Debug.Log("ERROR: Please add more positions in the posBags Array.");
    38.         return;
    39.     }
    40.     flagAvailable[indexBags] = false;
    41.     return     Vector3(posBags[indexBags].x,posBags[indexBags].y, indexBags);
    42. }
    43.  
    44. function FreePosition(t : int){
    45.     flagAvailable[t] = true;
    46. }
    47. }
    48.  
    And that which I have translate: en C#


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PositionController : MonoBehaviour {
    6.  
    7.  
    8. private Vector2[] posBags;
    9. private Array flagAvailable;
    10. private int indexBags;
    11. private bool  toggleAllBags = false;
    12.  
    13. private GameObject[] objectsInBag;
    14.  
    15. void  Start (){
    16.  
    17.     objectsInBag = new GameObject[64];
    18.     flagAvailable = new Array();
    19.  
    20.     posBags = [Vector2(195,260), Vector2(195,465), Vector2(385,260), Vector2(385,465)];
    21.     for( int i= 0; i < posBags.length; i++){
    22.         flagAvailable.Push(true);
    23.     }
    24.     indexBags = 0;
    25. }
    26. }
    27.  
    28.     void  Update (){
    29.  
    30.    
    31.     }
    32.  
    33.  
    34.  
    35.     //returns a position that is available to show a selected bag.
    36.     void  GetPositionAvailable (){
    37.         bool  found = false;
    38.         for(indexBags = 0; indexBags < flagAvailable.length; indexBags++){
    39.             if(flagAvailable[indexBags]){
    40.                 found = true;
    41.                 break;
    42.             }
    43.         }
    44.         if(!found){
    45.             Debug.Log("ERROR: Please add more positions in the posBags Array.");
    46.             return;
    47.         }
    48.         flagAvailable[indexBags] = false;
    49.         return     Vector3(posBags[indexBags].x,posBags[indexBags].y, indexBags);
    50.     }
    51. void  FreePosition ( int t  ){
    52.     flagAvailable[t] = true;
    53. }
    54. }
    55.  
    56.  
    I thus have plusior error
    on the line 20 in C#

    error CS1525: Unexpected symbol “[”

    then I have

    Standard The gold namespace name “Array” could not Be found. Does are you missing have using directing gold year assembly refers
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
  3. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    One must write this way in C# script?

    It is Javascript
    function Start and VAr

    I will look at, but if somebody to translate it into C# I could help me would be recognize!

    Code (csharp):
    1.  
    2. function Start () {
    3. var arr = new [URL='http://docs.unity3d.com/ScriptReference/Array.html']Array[/URL] ();
    4.  
    5.  
    6. // Add one element
    7. arr.Push ("Hello");
    8.  
    9. // print the first element ("Hello")
    10. print(arr[0]);
    11.  
    12.  
    13. // Resize the array
    14. arr.length = 2;
    15. // Assign "World" to the second element
    16. arr[1] = "World";
    17.  
    18. // iterate through the array
    19. for (var value : [URL='http://docs.unity3d.com/ScriptReference/String.html']String[/URL] in arr) {
    20. print(value);
    21. }
    22. }
     
  4. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    Replace the line 20 to that :

    Code (CSharp):
    1. posBags = new Vector2[] {new Vector2(195,260),new Vector2(195,465), new Vector2(385,260),new Vector2(385,465)};
     
  5. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    With exact! Javais not to think of doing that!
    Thank you very much TSnake!

    You would have an idea to replace Array of script in java for C#?

    Here the idea that I have write in script in C#
    It there there ace more error But not so on it goes! ^^
    Code (csharp):
    1.  
    2.     public int [] arrayOfInts;
    3.     private int flagAvailable;
    4.     private int indexBags;
    5.     private bool  toggleAllBags = false;
    6.     private Vector2 bagPos = new Vector2 (1400, 690);
    7.  
    8.     private GameObject[] objectsInBag;
    9.    
    10.  
    11.  
    12.  
    13.     public void  Start (){
    14.  
    15.         objectsInBag = new GameObject[40];
    16.         arrayOfInts[0] = 10;
    17.         arrayOfInts = new int [flagAvailable];
    18.      
    19.         bagPos = new Vector2 (1400, 690);
    20.         for( int i= 0; i < bagPos.x; i++){
    21.         flagAvailable.GetType();  
    22.         }
    23.         indexBags = 0;
    24.     }
     
  6. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    I have corrected the rest of the code that don't give me errors:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class PositionController : MonoBehaviour
    6. {
    7.  
    8.  
    9.     private Vector2[] posBags;
    10.     private List<bool> flagAvailable;
    11.     private int indexBags;
    12.     private bool toggleAllBags = false;
    13.  
    14.     private GameObject[] objectsInBag;
    15.  
    16.     void Start(){
    17.     objectsInBag = new GameObject[64];
    18.     List<bool> flagAvailable = new List<bool>();
    19.  
    20.     posBags = new Vector2[] {new Vector2(195, 260),new Vector2(195, 465),new Vector2(385, 260),new Vector2(385, 465) };
    21.     for( int i= 0; i < posBags.Length; i++){
    22.         flagAvailable.Add(true);
    23.     }
    24.     indexBags = 0;
    25. }
    26.  
    27.  
    28.     void Update()
    29.     {
    30.  
    31.  
    32.     }
    33.  
    34.  
    35.  
    36.     //returns a position that is available to show a selected bag.
    37.     Vector3 GetPositionAvailable()
    38.     {
    39.         bool found = false;
    40.         for (indexBags = 0; indexBags < flagAvailable.ToArray().Length; indexBags++)
    41.         {
    42.             if ((bool)flagAvailable.ToArray()[indexBags])
    43.             {
    44.                 found = true;
    45.                 break;
    46.             }
    47.         }
    48.         if (!found)
    49.         {
    50.             Debug.Log("ERROR: Please add more positions in the posBags Array.");
    51.             return(Vector3.zero);
    52.         }
    53.         flagAvailable[indexBags] = false;
    54.         return(new Vector3(posBags[indexBags].x, posBags[indexBags].y, indexBags));
    55.     }
    56.     void FreePosition(int t)
    57.     {
    58.         flagAvailable[t] = true;
    59.     }
    60. }
     
  7. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Here script translate into good C# for the moment any walk!
    the object this finds well as a child of the gameobject I will continue the tutoriel and I hold you with the juice if there is a problem on the level of the operation of both script ^^

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PositionController : MonoBehaviour {
    6.  
    7.     private Vector2[] posBags;//positions in the screen where the bags can be placed.
    8.     public int [] arrayOfInts;
    9.     private int flagAvailable;
    10.     private int indexBags;
    11.     private bool  toggleAllBags = false;
    12.     private Vector2 bagPos = new Vector2 (1400, 690);
    13.  
    14.     private GameObject[] objectsInBag;//represents all the objects in the bag.
    15.  
    16.  
    17.  
    18.  
    19.     public void  Start (){
    20.  
    21.         objectsInBag = new GameObject[40];
    22.         arrayOfInts[0] = 10;
    23.         arrayOfInts = new int [flagAvailable];
    24.      
    25.         bagPos = new Vector2 (1400, 690);
    26.         for( int i= 0; i < bagPos.x; i++){
    27.         flagAvailable.GetType();
    28.         }
    29.         indexBags = 0;
    30.     }
    31.  
    32.     void  Update (){
    33.  
    34.      
    35.     }
    36.  
    37.  
    38.  
    39.     //returns a position that is available to show a selected bag.
    40.     void  GetPositionAvailable (){
    41.         bool  found = false;
    42.         for  (indexBags = 0; indexBags < arrayOfInts.Length; indexBags++){
    43.             if(toggleAllBags){
    44.                 found = true;
    45.                 break;
    46.             }
    47.         }
    48.         if(!found){
    49.             Debug.Log("ERROR: Please add more positions in the posBags Array.");
    50.             return;
    51.         }
    52.         toggleAllBags = false;
    53.         new Vector3(posBags[indexBags].x,posBags[indexBags].y, indexBags);
    54.     }
    55.  
    56.     void  FreePosition ( int t  ){
    57.         toggleAllBags = true;
    58.     }
    59.     public void  SaveObjectInInventory ( GameObject obj  ){
    60.         for(int i = 0; i < objectsInBag.Length; i++){
    61.             if(objectsInBag[i] == null){
    62.                 objectsInBag[i] = obj;
    63.                 obj.transform.localPosition = Vector3.zero;
    64.                 obj.active = false;
    65.                 obj.transform.parent = transform;
    66.                 return;
    67.             }
    68.         }
    69.         Debug.Log("The inventory is full");
    70.     }
    71.  
    72. }
     
  8. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you very much TSnake! To have taken time to translate script!

    I will test what you have make, I think that you have me much more the surface with run of fits in C# that me thus I hold you with the juice if it goes!
     
  9. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you very much TSnake! I have to test it walks!
    I will continue the tutoriel and I you tien with the juices if that does not get out of order if I have difficulty!?
     
  10. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    If you have a problem with SaveObjectInInventory, add ref like this :

    Code (CSharp):
    1. public void SaveObjectInInventory(ref GameObject obj)
    beacause the C# without ref use a "copy" of the obj.

    And these scripts have the same name.
     
  11. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    With agreement in any case I do not have an error for the moment but I will write what you have me to advise!
    I hold you with the juice if I have another problem thank you still!
     
  12. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    There are things which I try to learn how to include/understand, in what you have to send to me, as regards List and add, I had intended some to speak but I did not know how to write it,
    On the other hand it is the first time that I see writing Vector3 in the place of Void in void GetPositionAvailable and also the return which is different
    Why one puts Vector3 instead of Void?
     
  13. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    "void" don't return value (null) but if you use "Vector3" that return a Vector3 value

    Example :
    Code (CSharp):
    1. public Transform test;
    2.  
    3. void Start()
    4. {
    5. gameObject.transform.postion = tranformToVector3(test); // = test.position
    6. }
    7. public Vector3 tranformToVector3(Transform transf)
    8. {
    9. return(transf.position); // That return a Vector3 value. tranformToVector3() = transf.position .
    10. }
    11.  
    For List<T> information look this: http://msdn.microsoft.com/en-US/en-en/library/6sh2ey19(v=vs.110).aspx

    a list of bool is writed List<bool> :

    Code (CSharp):
    1. List<bool> MyBoolList = new List<bool>() { true,false,true,false,false };
    And a list of any object is writed List<object>:

    Code (CSharp):
    1. List<object> MyList = new List<object>() { 1, 5.0f, new GameObject("A GameObject") /* ... */ };
     
  14. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    of agreement it is for step that returns to (null) and thus to transform a position vector3 ok should be used
     
  15. Jsmucker

    Jsmucker

    Joined:
    Sep 5, 2014
    Posts:
    48
    Also, you could always take a look at the Javascript to c# converters out there. They aren't perfect, so you may need to change up a few things. Here is a link to one:
    http://www.m2h.nl/files/js_to_c.php
     
    Last edited: Dec 15, 2014
  16. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Here the continuation in java and C#

    with script calls “inventoryGrid”

    I do not know if I correctly translated well because I have one alone error which says to me

    “Does UnityEngine.Vector3” does not contain have definition for “GetComponent” and No extension method “GetComponent” off standard “UnityEngine.Vector3” could Be found (are you missing has using directing gold year assembly refers?)

    in the script which makes calls with texture!

    Code (csharp):
    1.  
    2.  
    3.  
    4. private var posBags : Vector2[];
    5. private var flagAvailable : Array;
    6. private var indexBags : int;
    7. private var toggleAllBags : boolean = false;
    8.  
    9. private var objectsInBag : GameObject[];
    10.  
    11.  
    12. function Start(){
    13.  
    14.     objectsInBag = new GameObject[64];
    15.     flagAvailable = new Array();
    16.  
    17.     posBags = [Vector2(195,260), Vector2(195,465), Vector2(385,260), Vector2(385,465)];
    18.     for( var i = 0; i < posBags.length; i++){
    19.         flagAvailable.Push(true);
    20.     }
    21.     indexBags = 0;
    22. }
    23.  
    24. function Update(){
    25.  
    26.  
    27.     if(Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.B)){
    28.         for(var child : Transform in transform){
    29.             if(child.GetComponent(InventoryGrid) == null){
    30.                 break;
    31.             }
    32.             if(toggleAllBags){
    33.                 child.GetComponent(InventoryGrid).HideBag();
    34.             } else {
    35.                 if(!child.GetComponent(InventoryGrid).BagIsBeingDisplayed()){
    36.                     child.GetComponent(InventoryGrid).ShowBag();
    37.                 }
    38.             }
    39.         }
    40.         if(toggleAllBags)
    41.             toggleAllBags = false;
    42.         else
    43.             toggleAllBags = true;
    44.  
    45.  
    46. function GetPositionAvailable(){
    47.     var found : boolean = false;
    48.     for(indexBags = 0; indexBags < flagAvailable.length; indexBags++){
    49.         if(flagAvailable[indexBags]){
    50.             found = true;
    51.             break;
    52.         }
    53.     }
    54.     if(!found){
    55.         Debug.Log("ERROR: Please add more positions in the posBags Array.");
    56.         return;
    57.     }
    58.     flagAvailable[indexBags] = false;
    59.     return     Vector3(posBags[indexBags].x,posBags[indexBags].y, indexBags);
    60. }
    61.  
    62. function FreePosition(t : int){
    63.     flagAvailable[t] = true;
    64. }
    65.  
    66.  
    67. function SaveObjectInInventory(obj : GameObject){
    68.     for(var i : int = 0; i < objectsInBag.length; i++){
    69.         if(objectsInBag[i] == null){
    70.             objectsInBag[i] = obj;
    71.             obj.transform.localPosition = Vector3.zero;
    72.             obj.active = false;
    73.             obj.transform.parent = transform;
    74.             return;
    75.         }
    76.     }
    77.     Debug.Log("The inventory is full");
    78. }
    79.  
    80. function GetObjectsInBag(t : int){
    81.     return objectsInBag[t];
    82. }
    83. function SetObjectInBag(t : int, obj : GameObject){
    84.     objectsInBag[t] = obj;
    85.     }
    86.     }
    87.  
    Here the translation which I have to continue thanks to TSnake in C#

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class PositionController : MonoBehaviour
    7. {
    8.  
    9.  
    10.     private Vector2[] posBags;
    11.     private List<bool> flagAvailable;
    12.     private int indexBags;
    13.     private bool toggleAllBags = false;
    14.  
    15.     private GameObject[] objectsInBag;
    16.  
    17.     void Start(){
    18.         objectsInBag = new GameObject[64];
    19.         List<bool> flagAvailable = new List<bool>();
    20.    
    21.         posBags = new Vector2[] {new Vector2(195, 260),new Vector2(195, 465),new Vector2(385, 260),new Vector2(385, 465) };
    22.         for( int i= 0; i < posBags.Length; i++){
    23.             flagAvailable.Add(true);
    24.         }
    25.         indexBags = 0;
    26.     }
    27.  
    28.  
    29.     public void Update()
    30.     {
    31.                 if (Input.GetKey (KeyCode.LeftShift) && Input.GetKeyDown (KeyCode.B)) {//pressed Shift + B
    32.                         foreach (Transform child in transform) {
    33.                                 if (child.GetComponent<InventoryGrid> ()) {
    34.                                         break;
    35.                                 }
    36.                                 if (toggleAllBags) {
    37.                                         child.GetComponent<InventoryGrid> ().HideBag ();
    38.                                 } else {
    39.                                         if (!child.GetComponent<InventoryGrid> ().BagIsBeingDisplayed ()) {//make sure that the bag isnt being displayed already.
    40.                                                 child.GetComponent<InventoryGrid> ().ShowBag ();
    41.                                         }
    42.                                 }
    43.                         }
    44.                         if (toggleAllBags)
    45.                                 toggleAllBags = false;
    46.                         else
    47.                                 toggleAllBags = true;
    48.                 }
    49.         }
    50.  
    51.     //returns a position that is available to show a selected bag.
    52.     Vector3 GetPositionAvailable()
    53.     {
    54.         bool found = false;
    55.         for (indexBags = 0; indexBags < flagAvailable.ToArray().Length; indexBags++)
    56.         {
    57.             if ((bool)flagAvailable.ToArray()[indexBags])
    58.             {
    59.                 found = true;
    60.                 break;
    61.             }
    62.         }
    63.         if (!found)
    64.         {
    65.             Debug.Log("ERROR: Please add more positions in the posBags Array.");
    66.             return(Vector3.zero);
    67.         }
    68.         flagAvailable[indexBags] = false;
    69.         return(new Vector3(posBags[indexBags].x, posBags[indexBags].y, indexBags));
    70.     }
    71.     void FreePosition(int t)
    72.     {
    73.         flagAvailable[t] = true;
    74.     }
    75.  
    76.     public void  SaveObjectInInventory (  GameObject obj  ){
    77.         for(int i = 0; i < objectsInBag.Length; i++){
    78.             if(objectsInBag[i] == null){
    79.                 objectsInBag[i] = obj;
    80.                 obj.transform.localPosition = Vector3.zero;
    81.                 obj.active = false;
    82.                 obj.transform.parent = transform;
    83.                 return;
    84.             }
    85.         }
    86.         Debug.Log("The inventory is full");
    87.     }
    88.     public Vector3 GetObjectsInBag(int t){
    89.         return objectsInBag [t];
    90.     }
    91.     public Vector3  SetObjectInBag ( int t ,   GameObject obj  ){
    92.         objectsInBag[t] = obj;
    93.     }
    94. }
    95.  
    Here the paragraph or one makes calls with Script “ObjectInfo” Script Java

    Code (csharp):
    1.  
    2. function Bag(posX : float, posY : float, sX : float, sY : float){
    3.         GUI.BeginGroup (Rect (Screen.width - posX, Screen.height - posY, sX, sY));
    4.         GUI.Box (Rect(0,0,sX,sY), bagName);
    5.    
    6.         for( var i = 0; i < 5; i++){
    7.             for( var j = 0; j < 8; j++){
    8.                 if(ctrl.GetObjectsInBag(offsetBag+(4*i)+j) == null){
    9.                     tmpTexture = defaultTextureSlot;
    10.                 }else{
    11.                     tmpTexture = ctrl.GetObjectsInBag(offsetBag +(4*i)+j).GetComponent(ObjectInfo).iconTexture;
    12.  
    13.                 }
    14.                 if(GUI.Button (Rect(slotSize * j + spacingBetweenSlots * (j+1)+10, slotSize * i + spacingBetweenSlots*(i+1)+ 15, slotSize, slotSize), tmpTexture)){
    15.                 }
    16.             }
    17.         }
    18.         GUI.EndGroup ();
    19.     }
    20.     function BagIsBeingDisplayed(){
    21.      
    22.         return showBag;
    23.         }
    24.  
    in C#

    Code (csharp):
    1.  
    2.     public void  Bag ( float posX ,   float posY ,   float sX ,   float sY  ){
    3.         GUI.BeginGroup (new Rect (Screen.width - posX, Screen.height - posY, sX, sY));
    4.         GUI.Box (new Rect(0,0,sX,sY), bagName);
    5.    
    6.         for( int i = 0; i < 5; i++){
    7.             for( int j = 0; j < 8; j++){
    8.                 if(ctrl.GetObjectsInBag(offsetBag+(4*i)+j) == null){
    9.                     tmpTexture = defaultTextureSlots;
    10.                 }else{
    11.                     tmpTexture = ctrl.GetObjectsInBag(offsetBag +(4*i)+j).GetComponent<ObjectInfo>().iconTexture;
    12.  
    13.                 }
    14.                 if(GUI.Button (new Rect(slotSize * j + spacingBetweenSlots * (j+1)+10, slotSize * i + spacingBetweenSlots*(i+1)+ 15, slotSize, slotSize), tmpTexture)){
    15.                 }
    16.             }
    17.         }
    18.         GUI.EndGroup ();
    19.     }
    20.     public bool BagIsBeingDisplayed(){
    21.      
    22.         return showBag;
    23.         }
     
  17. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Thank you for the bond it east interest, but as you say that translated not all but thank you these useful
     
  18. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    somebody can help me I find any answer to this problem, I seeks in vain I do not find thank you in advance!
     
  19. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    Hello again !

    I have find these errors :

    Code (CSharp):
    1.  public GameObject GetObjectsInBag(int t)
    2.   {
    3.   return objectsInBag[t]; // Your fonction have return a GameObject but your output was a Vector3 and it can't convert a GameObejct to Vector3.
    4.   }
    5.   public void SetObjectInBag(int t, GameObject obj)
    6.   {
    7.   objectsInBag[t] = obj; // You haven't have a "return (Vector3 Value)" so you need to use void.
    8.   }
     
  20. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Of agreement!! you are a genius! Oula I was there at all there!
    I have to seek by all on google, youtube, book impossible to find, I have thus to replace the script which you have to correct now “GetComponent” Walks well except that my inventory is not posted any more and gives me that in error:

    Code (csharp):
    1.  
    2. IndexOutOfRangeException: Array index is out off arranges.
    3. PositionController.GetObjectsInBag (Int32 T) (At Assets/CharacterSystem/Character_System/Scenes/PositionController.cs: 89)
    4. InventoryGrid.Bag (Individual posX, Individual posY, Individual sX, Individual sY) (At Assets/CharacterSystem/Character_System/Scenes/InventoryGrid.cs: 252)
    5. InventoryGrid.InventoryWindowMethod (Int32 windowId) (At
    6.  
    In the line of script:

    Code (csharp):
    1.  
    2.     public GameObject GetObjectsInBag (int T)
    3.     {
    4.         return objectsInBag [T]; // Your function cuts return has GameObject drank your output has Vector3 and it can' T convert has GameObejct to Vector3.
    5.     }
    6.  
    and that Ci:

    GUI Error: You are pushing more GUIClips than you are popping. Sour Make they are balanced)

    If my memory its good this error is with the number of GUI textures which is posted at the same time I have thus to post in the list (Bag Number) but nothing does not change like in my script of GUI textures but always similar strange for so much it to up to now work
    an idea?
     
  21. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    Address is larger than the size you used in a table.
    Code (CSharp):
    1. int[] test = new int[64];
    2. test[65] = 1;
    You have an error in the Unity3D console because you edit with a adress highest of the size.
    Set a higher size or use a lowere adress.
    And for the GUI I don't know beacause I don't use longer the old GUI but I use the newest (Unity 4.6 new UI system). Maybe here : http://docs.unity3d.com/Manual/comp-UnityGUIGroup.html or here http://docs.unity3d.com/ScriptReference/GUI.html or http://docs.unity3d.com/Manual/GUIScriptingGuide.html
     
  22. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    You want to say the number of box that contien the inventory?
    But I must put this code in what exactly?
    Because the box which is preset sound " ObjectinBag which is GameObject, and it or it there with the error of GetObjectsInBag, I very did not include/understand to look at my inventory if that can you help!

    Thank you still!

    http://forum.unity3d.com/threads/how-to-make-an-inventory-of-what-style.283826/
     
  23. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I have the head which smoke I do not arrive has to find the solution somebody can help me if you like it?
     
  24. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Good after a day of research I have to find or was to it the problem the problem is here:
    Code (csharp):
    1.  
    2.     void Start () {
    3.         offsetBag = bagNumber * (int) numSlots;
    4.  
    5.         ctrl = transform.parent.GetComponent<PositionController> ();
    6.         indexOnController = 0;
    7.     }
    8.  
    If we use the inspector option debug, I could see that multiplies the numslot and offsetBag and thus if I use the variable

    Code (csharp):
    1.  
    2. private float numSlot = 2;
    3. and BagNumber which admit is to 10
    4. the computer thus will calculate 2 X 10 = 20
    5.  
    and thus the offsetBag and larger than BagNumber of or the posting of error!
    It had to seem to me well to have already seen this error but the writing was different!

    Good in all that it is quite beautiful to have to find but blow while following the tutoriel the posting of the image in the inventory does not go! Thus I will continue to seek if there are ideas not to hesitate not!
     
  25. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    Hello again!

    I do not have still to find why “iconTexture” do not appear in the inventory whereas I make well thus call with script “ObjectInfo” I make call with you to be on I correctly translated the Script java?

    Thank you in advance

    Code (csharp):
    1.  
    2. var iconTexture : Texture;
    3. var nameOfObj : String = "Put your Object name";
    4. var inventory : GameObject; //represents a reference to our inventory
    5.  
    6. private var decr : boolean;
    7.  
    8. function Start(){
    9.     decr = false;  
    10. }
    11.  
    12. function OnMouseOver(){
    13.  
    14.     ToggleAlpha(0.3f,1);
    15.     if(Input.GetMouseButtonDown(0)){
    16.         renderer.material.color.a = 1;
    17.         inventory.GetComponent(PositionController).SaveObjectInInventory(transform.gameObject);  
    18.     }  
    19. }
    20.  
    21. function OnMouseExit(){
    22.     renderer.material.color.a = 1;
    23. }
    24.  
    25. function ToggleAlpha(minV : float, maxV : float){
    26.     if(renderer.material.color.a > minV && decr){
    27.         renderer.material.color.a -= 1*Time.deltaTime;  
    28.     } else {
    29.         renderer.material.color.a += Time.deltaTime;
    30.     }
    31.     if(renderer.material.color.a > maxV){
    32.         decr = true;  
    33.     } else if(renderer.material.color.a < minV){
    34.         decr = false;
    35.     }
    36. }
    37.  
    Script C#

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class ObjectInfo : MonoBehaviour {
    7.  
    8.     public Texture iconTexture;
    9.     public string nameOfObj;
    10.     public GameObject inventory;
    11.     private bool decr;
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.         decr = false;
    16.  
    17.     }
    18.    
    19.     // Update is called once per frame
    20.     void Update () {
    21.    
    22.     }
    23.     public void OnMouseOver(){
    24.                 ToggleAlpha (0.3f,1);
    25.                 if (Input.GetMouseButtonDown (0)) {
    26.  
    27.             Color color = renderer.material.color;
    28.             color.a = 1f;
    29.             renderer.material.color = color;
    30.             inventory.GetComponent<PositionController>().SaveObjectInInventory(transform.gameObject);  
    31.  
    32.         }
    33.         }
    34.     void OnMouseExit (){
    35.         Color color = renderer.material.color;
    36.         color.a = 1f;
    37.         renderer.material.color = color;
    38.         }
    39.  
    40.  
    41.  
    42.     void  ToggleAlpha ( float minV ,   float maxV  ){
    43.         if(renderer.material.color.a > minV && decr){
    44.             Color color = renderer.material.color;
    45.             color.a -= 1f*Time.deltaTime;  
    46.             renderer.material.color = color;
    47.         } else {
    48.             Color color = renderer.material.color;
    49.             color.a += Time.deltaTime;
    50.             renderer.material.color = color;
    51.         }
    52.         if(renderer.material.color.a > maxV){
    53.             decr = true;  
    54.         } else if(renderer.material.color.a < minV){
    55.             decr = false;
    56.         }
    57.     }
    58. }
    59.  
     
  26. TSnake

    TSnake

    Joined:
    Mar 12, 2014
    Posts:
    13
    You use that on C#:
    Code (CSharp):
    1.             Color color = renderer.material.color;
    2.             color.a -= 1f*Time.deltaTime;
    3.             renderer.material.color = color;
    but on javascript you only use that
    Code (JavaScript):
    1.         renderer.material.color.a -= 1*Time.deltaTime;  
    I don't understand why.

    EDIT: I have understand beacause you can't use like of javascript.

    But I don't know why you redefine color whenever ?
    You don't need to redefine the color.

    And are you using a Mesh Renderer because GUI Texture don't use renderer but guitexture ?
     
    Last edited: Dec 17, 2014
  27. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    To yes, I do not manage to make walk this paragraph and I had fun to test operation I have just to forget to rectify the paragraph…

    For texture I do not use GUI textures all is made with method GUI then I use a variable of Texture and I stick my image in the inspector!
    You think that it is for that that does not go?
    I followed the tutoriel of Design and him it goes with exactly the same code except that it is to him in java
    I do not have still to find solution

    Look at my inventory here to give you an idea
    http://forum.unity3d.com/threads/how-to-make-an-inventory-of-what-style.283826/
     
  28. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    And to answer your question about rendererMaterial I want to thus make clinioter the object in C# I am to oblige to mark that so that it goes
     
  29. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    they is good I succeeded in solving the problem!!
    I hold you with the juice for the continuation because I have errors but I will continue the tutoriel to see whether I succeeded in Thank you very much solving them still of your assistance!
    I would start again if I have evil to translate the java!
    And if I can help you on something hessite not!
     
  30. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I thus have as a follow-up the tutoriel but here another problem that I meet, on the “GUITexture” unfortunately while following what is known as I do not have anything which goes.
    Normally if I click on the icon of my inventory my cursor should post GUITexture!
    I also realized that I had to forget to translate two paragraph in script “InventoryGrid”

    here the java and C#:

    JavaScript :

    Code (csharp):
    1.  
    2. function HideBag(){
    3.     showBag = false;
    4.     ctrl.FreePosition(indexOnController);
    5. }
    6.  
    7. function ShowBag(){
    8.     showBag = true;
    9.     var info : Vector3 = ctrl.GetPositionAvailable();
    10.     indexOnController = info.z;//position available for releasing when whe hide this bag
    11.     bagPos = Vector2(info.x,info.y);//coords of the position available.
    12. }
    13.  
    C# :
    Code (csharp):
    1.  
    2.     public void  HideBag (){
    3.         showBag = false;
    4.         ctrl.FreePosition(indexOnController);
    5.     }
    6.    
    7.     public void  ShowBag (){
    8.         showBag = true;
    9.         Vector3 info = ctrl.GetPositionAvailable();
    10.         indexOnController = (int)info.z;//position available for releasing when whe hide this bag
    11.         bagPos = new Vector2(info.x,info.y);//coords of the position available.
    12.     }
    13.  
    14.  
    to be sure that the code is correct…
    Because following that I have two error which says to me:

    The code with was already translated (to be seen higher of my post)

    NullReferenceException: Object refers not set to year authority off year object
    PositionController.GetPositionAvailable () 55: line 5



    Code (csharp):
    1.  
    2.     public Vector3 GetPositionAvailable()
    3.     {
    4.         bool found = false;
    5.         for (indexBags = 0; indexBags < flagAvailable.ToArray().Length; indexBags++)
    6.         {
    7.             if ((bool)flagAvailable.ToArray()[indexBags])
    8.             {
    9.                 found = true;
    10.                 break;
    11.             }
    12.         }
    13.         if (!found)
    14.         {
    15.             Debug.Log("ERROR: Please add more positions in the posBags Array.");
    16.             return(Vector3.zero);
    17.         }
    18.         flagAvailable[indexBags] = false;
    19.         return(new Vector3(posBags[indexBags].x, posBags[indexBags].y, indexBags));
    20.         return (Vector3.zero);
    21.     }
    22.     public void FreePosition(int t)
    23.     {
    24.         flagAvailable[t]= true;
    25.     }
    26.  
    27.  
    InventoryGrid.ShowBag () (at line 5

    Code (csharp):
    1.  
    2.  
    3.     public void  ShowBag (){
    4.         showBag = true;
    5.         Vector3 info = ctrl.GetPositionAvailable();
    6.         indexOnController = (int)info.z;//position available for releasing when whe hide this bag
    7.         bagPos = new Vector2(info.x,info.y);//coords of the position available.
    8.     }
    9.  
    10.  
    11.  
    InventoryGrid.ToggleBag () (at line 7

    Code (csharp):
    1.  
    2.     public void ToggleBag()
    3.     {
    4.         if (showBag) {
    5.             HideBag ();
    6.         } else {
    7.             ShowBag ();
    8.         }
    9.     }
    10.  
    InventoryGrid.InventoryWindowMethod
    Code (csharp):
    1.  
    2.             ToggleBag();
    3.  
    Normally this error please say to me which misses something with my line which does not find, the variable or the component…
    or to write “no one” or is not to affect or to change the void but I have anything to find in use that… Then in the tutoriel nothing is to add in this kind…
    With can my opinion it east be also on the level of the somebody translation to an idea?
     
    Last edited: Dec 18, 2014
  31. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    I have to find why that beug this line prevents from making function GUItexture when have clicks there above, therefore I will try to find the solution but if somebody has an idea I want to know well why that do that
    Code (csharp):
    1.  
    2.                 if (GUI.Button (new Rect (slotSize * j + spacingBetweenSlots * (j + 1) + 10, slotSize * i + spacingBetweenSlots * (i + 1) + 15, slotSize, slotSize), tmpTexture)) {
     
  32. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    They is good the problem is solved