Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Help

Discussion in 'Getting Started' started by cookiegod19, Mar 3, 2024.

  1. cookiegod19

    cookiegod19

    Joined:
    Mar 2, 2024
    Posts:
    6
    The problem is that there are 6 errors which 4 of them say I need this " ; " and 2 say " New line in constant " please someone fix this. Here is the script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerSprint : MonoBehaviour
    6. {
    7.  
    8.     float ifSprinting = Input.GetAxis("Sprint")
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.  
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if (ifSprinting = 0)
    20.         {
    21.             PlayerMovement.OrdinarySpeed()';
    22.        }
    23.        else
    24.        {
    25.            PlayerMovement.AddSpeed()';
    26.         }
    27.  
    28.     }
    29. }
     
    Last edited: Mar 3, 2024
  2. levyomri10

    levyomri10

    Joined:
    Feb 23, 2022
    Posts:
    4
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerSprint : MonoBehaviour
    {

    float ifSprinting = Input.GetAxis("Sprint");

    // Start is called before the first frame update
    public void Start()
    {

    }

    // Update is called once per frame
    private void Update()
    {
    if (ifSprinting = 0)
    {
    PlayerMovement.OrdinarySpeed();
    }
    else
    {
    PlayerMovement.AddSpeed();
    }

    }
    }

    thats the best i can do since you need to have some method for "AddSpeed" "OrdinarySpeed" unless you are calling it from another script in which case the fix is probably there
     
  3. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    156
    you should go follow some tutorial, there are tons of not only wrong syntax but also flawed and incomplete logic in this script, it would be better if you start learning by following a tutorial
     
    cookiegod19 and levyomri10 like this.
  4. cookiegod19

    cookiegod19

    Joined:
    Mar 2, 2024
    Posts:
    6
    Will look at some tutorial.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,529
    Code like this isn't valid outside of a method, and even if it were it's missing the semi-colon at the end.
     
  6. KieranHarrington

    KieranHarrington

    Joined:
    Mar 5, 2024
    Posts:
    1
    Is everything good now?
     
    Last edited: Mar 18, 2024