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

error CS0149: Method name expected (help)

Discussion in 'Scripting' started by GoldenMine12, Oct 24, 2020.

  1. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    i wrote this code and got this error and i dont know what it means:

    Assets\animationStateController.cs(42,13): error CS0149: Method name expected

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class animationStateController : MonoBehaviour
    7. {
    8.     Animator animator;
    9.     int isWalkingHash;
    10.     int isRunningHash;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         animator = GetComponent<Animator>();
    16.         isWalkingHash = Animator.StringToHash("isWalking");
    17.         isRunningHash = Animator.StringToHash("isRunning");
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         bool isRunning = animator.GetBool(isRunningHash);
    24.         bool isWalking = animator.GetBool(isWalkingHash);
    25.         bool forwardPressed = Input.GetKey("w");
    26.         bool runPressed = Input.GetKey("left shift");
    27.  
    28.         if (!isWalking && forwardPressed)
    29.         {
    30.             animator.SetBool(isWalkingHash, true);
    31.         }
    32.  
    33.         if (isWalking && !forwardPressed)
    34.         {
    35.             animator.SetBool(isWalkingHash, false);
    36.         }
    37.  
    38.         if (!isRunning && (forwardPressed && runPressed))
    39.         {
    40.             animator.SetBool(isRunningHash, true);
    41.         }
    42.  
    43.         if (isRunning(!forwardPressed || !runPressed))
    44.         {
    45.             animator.SetBool(isRunningHash, false);
    46.         }
    47.     }
    48. }
    49.  
    50. [code]
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    With all due respect GoldenMine, You've been struggling on here for days with basic C# syntax questions. Sure, someone on the forums may be able to help you fix them. But you will soon run into another error and you'll have to come back. What will really help you is to gain an understanding of the code in front of you.

    You're here asking for a fish, but what you really need is to learn how to fish.

    I think you should start here: https://www.tutorialspoint.com/csharp/csharp_program_structure.htm
     
    Vryken and orionsyndrome like this.
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    if you wrote this code, have you thought about what this means?
    Code (csharp):
    1. isRunning(!forwardPressed || !runPressed)
    can you tell me what it's supposed to do?
     
    PraetorBlue likes this.
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Having seen your numerous threads, I think you're just milking the forum to customize your borrowed code, and without expending energy to even bother learning anything. It's not against the law, but it's not very nice either, especially when you write that you have written the code, and you clearly haven't. Not a single coder would miss out on such a repetitive pattern: i.e. every line before that one points to your error with a flashing sign. (Not to mention that IDE also highlights it with a red line.)
     
  5. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    it doesnt matter if i know or not what matters is that the community should help anyone that struggles because of people i start to understand what the errors mean and i have been able to fix some myself so if you dont want to help me thats fine just dont criticise me for the fact that i dont know what it means.
    p.s i followed a tutorial to write the code.
     
  6. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    and by the way even if i followed a tutorial to write the code i still wrote it its just not something i made
     
  7. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    and the fact that i need help does not mean that i am milking the forum it means that i need help
     
  8. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    and again if you don't want to help you don't have to
     
  9. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I'm trying to help you in the most effective way I think I can. I think you will gain a lot more understanding from going through basic tutorials than by tacking individual syntax errors ad-hoc.

    In any case it's really hard to help you with this particular problem because you haven't explained what you want the code to actually do. As Orion asked you above, and as I asked you two days ago when you posted a different thread for this same problem: https://forum.unity.com/threads/error-cs0149-method-name-expected-help.992603/#post-6446344

    So I could give you some advice to get rid of the syntax error, but it won't necessarily make the script work the way you want. For example, if you delete those lines with the error, the error will go away.
     
    Last edited: Oct 25, 2020
    Kurt-Dekker, orionsyndrome and Vryken like this.
  10. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    all i want to do is make my own game and with the help of the forum i can make my own game.
    sometimes even the best coder need help
     
  11. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    what i want the script to do is make the player move and change animation from idle to walking to running
     
  12. GoldenMine12

    GoldenMine12

    Joined:
    Oct 22, 2020
    Posts:
    38
    and i already have the animations i just have to make the transition
     
  13. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    I never said that you don't want to make anything. I said that your methods of accomplishing your goals are relatively immoral, exactly because you expect to find free programmers -- not just help -- to fix your code, the code that looks like you've found it somewhere and modified it wrongly to suit your needs.

    Listen, I get that you're a kid, and still learning, and followed a tutorial. And this isn't my forum, and I wouldn't even mind this, because it does occur every day, in moderation. But you're spamming the forum with such requests. And my judgement is largely based on that.

    Yes, the forum should try to help you, not work for you. You are supposed to learn what you're doing, or ask for help to learn.

    My advice to you would be to begin by asking the basic questions that you seem to need more than just quick fixes. And this is what I expect to see from someone who is learning.

    Not "this is wrong, fix it", when your fix is literally in the line above.

    We aren't paid to do this, we aren't Unity's technical support, this is a community of likeminded people to share issues and solutions with Unity C# -- by spamming with malfunctioning code, you are diminishing the chance for everyone else to get answers for otherwise legit questions.

    Just change your attitude and everything is fine.
     
    Bunny83 and Vryken like this.