Search Unity

Unity Tutorial - 2D Side Scroller (Super Platformer Bros): error at 21:30

Discussion in 'Editor & General Support' started by Brian-Washechek, Jan 13, 2019.

  1. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    Help request.png As you can see in my image he has a Player_Move_Prot C# script and I do not. But we both have the asset, mine just doesn't want to show it's digital face. I see it under assets, it just isn't showing up when I search for it.
     
  2. What is that file between your "Player" and Prototype_1 scene assets? Is it possible you have named it differently?
     
  3. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    It looks like your script doesn't inherit MonoBehaviour.
     
  4. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player_ : MonoBehaviour
    6. {
    7.  
    8.     public int playerSpeed = 10;
    9.     public bool facingRight = true;
    10.     public int playerJumpPower = 1250;
    11.     public float moveX;
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         PlayerMove();
    17.     }
    18.  
    19.     void PlayerMove()
    20.     {
    21.         //CONTROLS
    22.         moveX = Input.GetAxis("Horizontal");
    23.         //ANIMATIONS
    24.         //PLAYER DIRECTION
    25.         if (moveX < 0.0f && facingRight == false)
    26.         {
    27.             FlipPlayer();
    28.         }
    29.         else if (moveX > 0.0f && facingRight == true)
    30.         {
    31.             FlipPlayer();
    32.         }
    33.         //PHYSICS
    34.         gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(moveX * playerSpeed, gameObject.GetComponent<Rigidbody2D>().velocity.y);
    35.     }
    36.  
    37.     void Jump()
    38.     {
    39.         //JUMPING CODE
    40.     }
    41.  
    42.     void FlipPlayer()
    43.     {
    44.  
    45.     }
    46. }
    47.  
    To Lurking-Ninja: I posted my code.
    To better_walk_away: Are you aware how I fix that?
     
    Last edited: Jan 13, 2019
  5. You need to have a matching filename with a matching class name.

    If you call your class Player_ than you need to place it in the Player_.cs.
    If you place it in the Player_Move.cs than you need to call your class Player_Move.

    After that when Unity compiles you should be able to attach it. But you also should have errors in the console. Please always check your console for errors.
     
  6. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    Well I've cleaned it up as well as I could. I've tried several times. The only thing I can think of is maybe because he's using MonoDevelop. I used to use that, but I recently learned that they stopped updating it so I now use plain Microsoft Visual Studio. The difference in our editors is all I can think of. I'm thinking the problem might have something to do with that. Maybe. But you can check out these pics of my project to see if that can get you anywhere to helping me.
    unity-tutorial-2d-side-scroller-super-platformer-bros error 1.png unity-tutorial-2d-side-scroller-super-platformer-bros error 2.png unity-tutorial-2d-side-scroller-super-platformer-bros error 3.png unity-tutorial-2d-side-scroller-super-platformer-bros error 4.png
    It's not even seeing the last one. I'm thinking the problem might have something to do with the last one, though. I don't see any errors. Luckily I have the kind souls on this forum to help out.

    "If you place it in the Player_Move.cs than you need to call your class Player_Move." I'm thinking that may be it. I don't know how to do that. Perhaps you could tell me. Maybe my pictures can help you to help me.
     
    Last edited: Jan 14, 2019
  7. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    Here are some screenshots of my game. What you said is probably true, I'm just not sure exactly how to do it. unity-tutorial-2d-side-scroller-super-platformer-bros error 1.png unity-tutorial-2d-side-scroller-super-platformer-bros error 2.png /*
    unity-tutorial-2d-side-scroller-super-platformer-bros error 3.png unity-tutorial-2d-side-scroller-super-platformer-bros error 4.png
     
  8. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    In your picture, I saw that your script wasn’t saved, please hit CTRL+S to save it. If this still doesn’t work, you can click the “Add Component”, then click “New script”, and then copy the code to the new script.