Some help please

I am a first time unity/C language user, and I am trying to create a script that moves an in-game sprite to the right using a video tutorial… When I hit the play button in unity, the button either do doesn’t darken at all or darkens but un-darkens whenever i push a movement key. here is my code. if any experienced c users could tell me what is wrong with my code that would be great.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

public float moveSpeed;

// Use this for initialization
public void Start() {

}

public void Update()
if (Input.getAxisRaw) (“Horizontal”) > .05f)

{
transform.Translate {new Vector3(Input.GetAxisRaw(“Horizontal”) * moveSpeed* Time.deltaTime, 0f, 0f};

};

Use topic titles that reflect the nature of the question and code tags please, it will help you in future.

1 Like

Here is your code formatted:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

    public float moveSpeed;

    // Use this for initialization
    public void Start () {

    }

    public void Update ()
    if (Input.getAxisRaw) ("Horizontal") >.05f)

{
    transform.Translate {
        new Vector3 (Input.GetAxisRaw ("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f
        };

    };

Firstly, you have a syntax error here; an extra right parenthesis:
if (Input.getAxisRaw) ("Horizontal") >.05f)

It should be:
if (Input.getAxisRaw("Horizontal") >.05f)

Secondly, you also have this line placed before the opening curly brace in your Update method.

Lastly, you don’t need to place semicolons after the closing curly braces for your methods and if-statements.

Make sure to read the error messages Unity logs in the console. Double-clicking on them will take you to the line in your script where the error is occurring.

1 Like