Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need Help

Discussion in 'Scripting' started by aktugegemen, Aug 23, 2023.

  1. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    i want upload a package on the asset store and i do 'Validate Package' thing and its give warning 'Check Type Namespaces' my simple jump script is that

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Jump : MonoBehaviour
    6. {
    7.     Rigidbody2D rb; //character's rigidbody2d
    8.     public int jumpspeed; //you can change it from editor its meaning is chracters jump speed
    9.     public bool ontheground = true; //to prevent it from jumping in the air
    10.  
    11.     private void Start()
    12.     {
    13.         rb = GetComponent<Rigidbody2D>(); //describe the component
    14.     }
    15.     private void OnCollisionEnter2D(Collision2D collision)
    16.     {
    17.         if (collision.gameObject.tag == "Ground") //check character on the ground
    18.         {
    19.             ontheground = true;
    20.         }
    21.     }
    22.     public void jump()
    23.     {
    24.         if (ontheground == true)
    25.         {
    26.             rb.velocity = new Vector2(rb.velocity.x, jumpspeed); //make the vertical move
    27.             ontheground = false; //say  the character on the air
    28.         }
    29.     }
    30. }
    31.  
    what i can do for remove the warning please help
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,874
    they may just want this to be put into a namespace

    https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/namespaces

    Honestly this is a 10 second google job and a very basic thing, and in addition to this the code you have posted has really bad syntax formatting such as naming "ontheground" instead of using proper casing

    So I would think twice about publishing an asset, its generally ideal to only publish stuff if you are an expert and can add value to peoples workflows rather than pollute the store with beginner level code
     
    Ryiah likes this.
  3. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,453
    Hopefully it's just a char controller in an art-only focused asset.
    I appreciate it when art assets include some controller in the demo scene to look around.
     
  4. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    I cannot solve my problem! The warning detail say

    types in your scripts (classes, interfaces, structs, enums) should be nested under a namespace block to prevent them from being mistaken for other potential types and for better organization as a whole

    I cant understand the when and where i use the "namespaces"
    Is there anything wrong if I don't fix it?
     
  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    711
    Ouch.. if you look at for example the unity code, or basically any code in an asset you will see their classes are in name spaces. google namespaces it has examaples for you.

    it just means that if you have a class of "myclass" and so do I, they wont clash and can be identified and both used
     
  6. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    Thanks for youre answer but now what can i do.
    I think there is no way to give warnings to me.
     
  7. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,833
    Add the three lines of code you see in the left mustard band:

     
    MadeFromPolygons and Ryiah like this.
  8. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    Thaaaank you so much youre king
     
  9. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    last question
    i have wrong scripts, can i do the same things twice ( i write namespace MyGame{} on top)
     
  10. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    711
    for your project you potentially dont need namespaces so no unity doesnt complain, but to play well with others, yes it does.. so that upload was your warning..
     
  11. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    thanks for reply
    i write namespace MyGame{} on top on all script do i true thing?
     
  12. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    711
    well you wouldnt put it on one line, you need to encase your classes in the {} so you might do it to all your code files and put them in the same namespace, or make more namespaces so like MyGame.UI or MyGame.Controls - as you're uploading a package to the store (from what you said) MyGame wouldnt really be the best namespace name, you might want your company name, or yourname.package so it is properly unique
     
  13. aktugegemen

    aktugegemen

    Joined:
    Dec 23, 2021
    Posts:
    12
    yes bro i know them :D
    i wanna say different thing but i cant, but i fix it thank you so much