Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

I met three problems in Unity

Discussion in 'Scripting' started by Bioshok2, May 1, 2014.

  1. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello everyone ,

    Please , help me, I met three problems on unity (I'm beginner) :(

    1) problem 1:
    when I enable gravity to my player , he falls ied through the platform , although I added a rigid body's assets and mesh colliders for both
    (player and platform) ( trigger is disabled) (I have not used code)

    2) problem 2:
    during the translation of the camera on the y axis, my water surface has no depth ( simple single circle ) , although I increased the maximum size of the surface water by y




    1) problem 3 (null reference exeption , whether in the case table or list) ( the code here )
    Thank you very much and good day.

    Cordially.
     
    Last edited: May 2, 2014
  2. xtremepman

    xtremepman

    Joined:
    Jul 18, 2012
    Posts:
    388
    1. Have you set the mesh for the mesh collider?
    2. NullReferenceException pops up when something isn't set to a value. Check the script in the inspector.
    3. Can you post a picture of the water surface? Note that Unity Free's water isn't particularly elegant :p
     
  3. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    1. Mesh colliders do not collide with other mesh colliders unless it is marked as convex.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Can you post the actual code that's generating the error? The code you posted won't even come close to compiling, and that's just from looking at it. You're referencing many variable names that don't exist anywhere, function calls are missing commas, you're missing semicolons in several places.... and so on. NullReferenceException is a runtime error, which means that whatever code is actually running in the game is, at least, compiling. Which tells me that what you posted is definitely not the code that's creating the error.

    Retyping a vague approximation of the code will make it pretty much impossible to diagnose your issue.
     
  5. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello,
    Here are the (unity free) water images.
    I will send you after my complete code.
    Thank you. $image1.PNG $image2.PNG
     
  6. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello,
    Sorry, the previous code was just an approximate example quickly (with errors)
    here is the actual code :



    Thank you .
     
    Last edited: May 2, 2014
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    ....Once again, that does not compile. Do you know how to see if something has compiled? Every line from 20 to 47 is not going to compile. Neither will 61 (x and X are different, commas don't work there), 64 (commas), 66 (commas), 73 (space between "Table" and "1", "distance Y *" is not okay), 92 (missing semicolon). Those are just the compile errors I can see at a quick glance.

    At this point, my recommendation is to look into some basic C# programming tutorials, because... I mean, everything about 20-47 is completely wrong. You need to learn how to use arrays. If you have ever learned how to use arrays, forget everything you've learned and start from the beginning. I cannot possibly emphasize how badly those lines are written. Not just syntax, but in basic understanding of how arrays work.
     
    Last edited: May 1, 2014
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    I've tried to guess what you were trying to do with this code. I think this will compile (I wrote it here in the text box so I haven't checked it), and will probably do what you were wanting it to do.

    This creates a 3-D "grid" of your prefab, with separate numbers for each of the dimensions.

    Code (csharp):
    1.  
    2. using UnityEngine ;
    3.  
    4. using System.Collections ;
    5.  
    6. using System.Collections.Generic ;
    7.  
    8.  
    9.  
    10.  
    11.  
    12. public class Platform: MonoBehaviour
    13.  
    14. {
    15. public int xCount = 5; //you don't want "static" here. "public" will let you edit it in the inspector though
    16. public int yCount = 1;
    17. public int zCount = 5;
    18.  
    19. public float distance = 50.0F ;
    20.  
    21.  
    22.  
    23. public Transform prefab ;
    24.  
    25. GameObject [] table;
    26.  
    27.  
    28.  
    29. void Start ()
    30.  
    31. {
    32.  
    33.  
    34.  
    35.  
    36. direction = new Vector3 ( 0.03f , 0.03f , 0.03f ) ;
    37.  
    38.  int a1=0;
    39. table = new GameObject[xCount * yCount * zCount];
    40.  
    41. for (int x = 0; x < xCount ; x ++)
    42. //I don't know what "number" was supposed to be. I'm guessing this was supposed to be a number of platforms spawned in each dimension
    43. {
    44.  
    45. for (int y = 0 ; y <yCount , y ++)
    46. {
    47.  
    48. for (int z = 0 ; z <zCount , z ++)
    49. {
    50.  
    51. table [ a1] = ( Instantiate ( prefab.gameObject , new Vector3 (x * distance , y * distance, z * distance ), Quaternion.identity ) ) as GameObject ;
    52.  
    53. a1 + + ;
    54. }
    55.  
    56.  
    57.  
    58.  
    59.  
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66. }
    67.  
    68. }
    69.  
    70. }
    71.  
    72. }
    73.  
    74.  
    75.  
    76.  
    77.  
    78.  
    79.  
    80. void Update ()
    81.  
    82. {
    83.  
    84.  
    85.  
    86. for (int a1 = 0; a1 < table.Length a1 + +)
    87.  
    88. {
    89.  
    90. table[a1].transform.Translate(direction.x*Time.deltaTime,direction.y*Time.deltaTime,direction.z*Time.deltaTime,Space.World);
    91.  
    92.            
    93.  
    94.         }
    95.  
    96. }
    97.  
    98.  
    99.  
    100. }
    101.  
    102. }
    103.  
     
  9. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hello StartManta.
    This code is currently incomplete (I modified several times now), but compiles anyway (not the first time but the second round).
    there's several gaps commas or other errors (x and X ...) in the copy paste (due to careless mistakes and tiredness), and instantiated objects and variables declared but not yet used 'is all I think.
    But otherwise, I would like to know the solution to the problem of null reference and the two others problems , thank you again :) .
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    How does that happen? I am getting the impression that you re-typed your code into the forum post....

    https://www.youtube.com/watch?v=c66pvfilotA
     
  11. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hi,
    First, sorry if my posts are badly written (I do not master English)
    Then I copy and paste from unity that is installed on another pc.
    may be due to google translation or some mistakes when copying and pasting.
     
  12. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    You're not running your code through Google Translate to post it here, are you...?
     
  13. Bioshok2

    Bioshok2

    Joined:
    Apr 14, 2014
    Posts:
    60
    Hi everyone :)
    Thank you.
    Yes, you were right Manta Star, your code worked well, and my code was whatever
    Sorry for the late reply and my code, I was too tired. Yesterday.
    I'll see after the other two problems.
    Otherwise I still have one other problem on unity, which I can not remember at the moment.
    Thank you and good day.