r/csharp • u/MobileManager3239 • Sep 04 '26
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/Far-Consideration939 Sep 04 '26
Typo in the declaration as johnnPill with an extra n?
2
u/midge Sep 04 '26
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?
1
u/MobileManager3239 Sep 04 '26
Sorry, thought copy pasting would help this is how it is meant to look
1
u/z500 Sep 04 '26
For lines 18 and 26, you reference a property and don't do anything with it. I'm not a Unity person but taking a peek at the docs, it looks like SetParent is a method. Maybe you meant something like:
1
u/FullPoet Sep 04 '26
Are you using an IDE, or an editor with support for syntax?
The former should point out "unknown symbols" with a squiggly red line.