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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

New to Unity 2d, and Im having trouble with scripting.

Discussion in '2D' started by Creo_Dasher, Jun 24, 2022.

Thread Status:
Not open for further replies.
  1. Creo_Dasher

    Creo_Dasher

    Joined:
    Jun 24, 2022
    Posts:
    2
    So, whats happening is:
    I have a button sprite.
    I have the baseinputmodule script
    I have no idea how to attach a script to an object.
    Clicking and dragging the script onto the object doesnt work because the script is of the class "Abstract"

    Also, i dont know C# coding at all if that has anyhting to do with it.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,963
    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried (include code, properly formatted!)
    - what you expected to happen
    - links to documentation you used to cross-check your work (CRITICAL!!!)
    - what actually happened, especially any errors you see

    You may edit your post above.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
    Last edited: Jun 24, 2022
  3. Creo_Dasher

    Creo_Dasher

    Joined:
    Jun 24, 2022
    Posts:
    2
    "Keep in mind the point of the Unity forum is not for us to write your script for you. It’s for YOU to write your script"

    I DONT KNOW CODING
    IS THAT AN ISSUE?

    "Do a little bit of basic research on your own. Double-click the actual error and try to see what code it relates to. Google the error text itself. Read at least two or three results."

    The error window has no elaboration, only the "OK" button. Google yields results, but they aren't helpful whatsoever.

    "Choose a good subject line. Don’t choose “Help!” or “Doesn’t work” Instead say “Need help with inventory system” or “Getting an X error when I pick up an item.” "

    If I'm gonna be specific on the issue. WHAT AM I SUPPOSED TO TYPE?

    "Identify at least the ballpark area where the error is in your code. Extract the relevant section of code, as little as you think will show the problem, and post it here."

    I already told you the ballpark, its attaching scripts to objects.

    "If you don’t post code, we can’t help you."

    WHAT CODE? I DONT KNOW CODE AND I CANT WRITE ANY OF IT UNTIL I ATTACH IT. ADDITIONALLY, THIS ISSUE DOESNT EVEN RELATE TO CODING WHATSOEVER.

    "1. What you think it should be doing

    2. What it actually is doing

    3. What things you have tried in order to fix it

    4. Any other interesting tidbits you think might be relevant"
    ----------------------------------------------------------------------------------------------------
    1. IDK! I don't know if you can even attach scripts to objects in the first place!

    2. Its giving me an error that i already mentioned.

    3. I cant try a fix if i dont know the problem.

    4. Ive given you all the relevant info that i have.
     
  4. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    491
    Yes you can. You don't need to attach a script to a gameobject to write it (or edit an existing script).
    Yes it does because you literally said:
    So you have a script therefore you should be able to just open the script file and then post the contents here.

    Yes you can. However a script must be of type MonoBehaviour for it to be attached to a gameobject.
     
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,002
Thread Status:
Not open for further replies.