Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug CS0246 ERROR Not letting me build my game

Discussion in 'Scripting' started by AfterCell2, May 13, 2024.

  1. AfterCell2

    AfterCell2

    Joined:
    May 10, 2024
    Posts:
    8
    Hi, wondering if someone can help.

    Basicly im trying to finally build my game but error CS0246 keeps popping up, I look in my scripts and its all correct and everything is name correctly with no spelling mistakes, iv refreshed it and cleaned and reimported my assets however nothing is seeming to work and its not even showing and error when i go into the script its just popping up in console when i try to build the game.

    if someone knows how to fix this i would love some help its a 2D game and the script that isnt working is for a CharacterController2D.
     
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,215
    perhaps you could share the full error and the code (in code tags) most of us dont memorise error numbers, and wont feel inclined to google it for you, without the code to go with (note it will tell you where and what is wrong)
     
  3. AfterCell2

    AfterCell2

    Joined:
    May 10, 2024
    Posts:
    8
    Yeah that makes more sense the full thing is

    Assets\Scripts\PlayerMovement.cs(9,12): error CS0246: The type or namespace name 'CharacterController2D' could not be found (are you missing a using directive or an assembly reference?)

    and the code is

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using System;
    public class PlayerMovement : MonoBehaviour
    {
    public CharacterController2D controller;
    public Animator animator;
    public GameOver GameOverScreen;
    public float runSpeed = 40f;
    float horizontalMove = 0f;
    bool jump = false;
    bool crouch = false;
    void Update()
    {
    horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
    animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
    if (Input.GetButtonDown("Jump"))
    {
    jump = true;
    animator.SetBool("IsJumping", true);
    }
    if (Input.GetButtonDown("Crouch"))
    {
    crouch = true;
    } else if (Input.GetButtonUp("Crouch"))
    {
    crouch = false;
    }
    }
    public void OnLanding()
    {
    animator.SetBool("IsJumping", false);
    }
    void FixedUpdate()
    {
    // Move Our Character
    controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
    jump = false;
    }
    }
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,215
    shame about the lack of code tags, OK so wtf is CharacterController2D ?
     
  5. AfterCell2

    AfterCell2

    Joined:
    May 10, 2024
    Posts:
    8
    Dont really know what a code tag is mate only started all of this like 2 weeks ago

    and the CharacterController2D is just to make it so the Player can move its only a 2D game so its only got basic left and right movement so the code is not that complicated but i have no clue why this error is happening
     
  6. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,215
    code tags are these
    upload_2024-5-13_23-13-58.png

    makes your code come out all pretty and readable

    again though, what is CharacterController2D?
     
  7. AfterCell2

    AfterCell2

    Joined:
    May 10, 2024
    Posts:
    8
    Its just a basic script that allows the player to see if it is grounded between Jumping running and walking with the animations
     
  8. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,215
    well it hates it, so clearly something about it makes it hate it..
     
  9. AfterCell2

    AfterCell2

    Joined:
    May 10, 2024
    Posts:
    8
    yup and i have no clue what it hates because when i delted the script as all it would do is stop animations and i would be able to fix that it ened up stoping movement completely and i have no clue why
     
  10. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,215
    well as the person with only the text on this thread to go by, how would you expect any of us to know? but the above script looks like it used the controller to move.. so, no, it probably doesnt now cos there is no controller to move it..

    Ive no idea what your 2d controller script was or where you found it, or anything because you havent shared..