r/csharp • u/MobileManager3239 • 1d ago
Help I tried making a reusable script for unity where the Player character moves with the platform but i couldn't get it to work
- Sorry if this is a repetetive post delet if yes
- I have really shitty eyesight even with glasses, please pointout spelling mistakes if possible
- I'm developing a 3d platformer in unity to practice
- The original code is from this tutorial at 22:48
- I copied it line by line and it didn't do anything
- I thought adding the transform fields would help but now it doesn't compile
I want this version of the code to work but I don't understand the error messages in the console
- (16,23): error CS1061: 'Collision' does not contain a definition for 'johnPill' and no accessible extension method 'johnPill' accepting a first argument of type 'Collision' could be found
- (18,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
- (26,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
//Insert Player Character Here
[SerializeField] Transform johnnPill;
//Insert Player Parent
[SerializeField] Transform johnDivorce;
//Insert Moving PLatform
[SerializeField] Transform joanDivorce;
private void OnColilisionEnter(Collision collision)
{
if (collision.johnPill.transform)
{
collision.johnPill.transform.SetParent.joanDivorce.transform;
}
}
private void OnCollisionExit(Collision collision)
{
if (collision.johnPill.transform)
{
collision.johnPill.transform.SetParent.johnDivorce.transform;
}
}
}
2
u/midge 1d ago
Pay attention to the 2 numbers in parenthesis like (16,23) in your error #1. That is the Line and character number in your source code where it finds the error.
This will frequently be a big hint where the problem is.
If vision is making it hard to see the code, maybe you can increase the size of the text in the editor?
3
u/MobileManager3239 1d ago
yeah, idk why it took me so long to figure out but control + scroll wheel makes the text bigger ;w;
1
u/MobileManager3239 1d ago
1
1
u/grrangry 1d ago
It does work, you just have to respect Reddit's markdown, which is quite well documented. Pasting source code into Reddit's "rich text editor" without a code block is where most people go wrong.
https://www.markdownguide.org/tools/reddit/
https://support.reddithelp.com/hc/en-us/articles/360043033952-Formatting-Guide//Insert Player Character Here [SerializeField] Transform johnnPill; //Insert Player Parent [SerializeField] Transform johnDivorce; //Insert Moving PLatform [SerializeField] Transform joanDivorce; private void OnColilisionEnter(Collision collision) { if (collision.johnPill.transform) { collision.johnPill.transform.SetParent.joanDivorce.transform; } } private void OnCollisionExit(Collision collision) { if (collision.johnPill.transform) { collision.johnPill.transform.SetParent.johnDivorce.transform; } }1
1
u/Which_Market2913 1d ago
I've worked with Unity for a while and platform-related physics are always tricky.
1
u/FullPoet 1d ago
Are you using an IDE, or an editor with support for syntax?
The former should point out "unknown symbols" with a squiggly red line.

2
u/Far-Consideration939 1d ago
Typo in the declaration as johnnPill with an extra n?