I met three problems in Unity

Hello everyone ,

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

  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

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

Cordially.

  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 :stuck_out_tongue:
  1. Mesh colliders do not collide with other mesh colliders unless it is marked as convex.

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.

Hello,
Here are the (unity free) water images.
I will send you after my complete code.
Thank you.

Hello,
Sorry, the previous code was just an approximate example quickly (with errors)
here is the actual code :

Thank you .

…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.

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.

using UnityEngine ;

using System.Collections ;

using System.Collections.Generic ;

 

 

public class Platform: MonoBehaviour

{
public int xCount = 5; //you don't want "static" here. "public" will let you edit it in the inspector though
public int yCount = 1;
public int zCount = 5;

public float distance = 50.0F ;

 

public Transform prefab ;

GameObject [] table;

 

void Start ()

{

 


direction = new Vector3 ( 0.03f , 0.03f , 0.03f ) ;

 int a1=0;
table = new GameObject[xCount * yCount * zCount];

for (int x = 0; x < xCount ; x ++) 
//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
{

for (int y = 0 ; y <yCount , y ++)
{

for (int z = 0 ; z <zCount , z ++)
{

table [ a1] = ( Instantiate ( prefab.gameObject , new Vector3 (x * distance , y * distance, z * distance ), Quaternion.identity ) ) as GameObject ;

a1 + + ;
}

 

 

 

 

 

}

}

}

}

 

 

 

void Update ()

{

 

for (int a1 = 0; a1 < table.Length a1 + +)

{

table[a1].transform.Translate(direction.x*Time.deltaTime,direction.y*Time.deltaTime,direction.z*Time.deltaTime,Space.World);

            

        }

}

 

}

}

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 :slight_smile: .

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

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.

You’re not running your code through Google Translate to post it here, are you…?

Hi everyone :slight_smile:
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.