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

Assets\Scripts\SwordBehaviour.cs(17,6): error CS1513: } expected

Discussion in 'Scripting' started by RadioactiveChickenGames1, Oct 30, 2020.

  1. RadioactiveChickenGames1

    RadioactiveChickenGames1

    Joined:
    Sep 29, 2020
    Posts:
    15
    I am getting this error and I don't know why! Can someone please help? Thanks in advance! Here is the code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class SwordBehaviour : MonoBehaviour
    {
    public GameObject player;
    public PlayerBehaviour script;
    // Start is called before the first frame update
    void Start()
    {
    script = player.GetComponent<PlayerBehaviour>();
    }
    // Update is called once per frame
    void Update()
    The line that apparently has the error-> {
    private float nerp = 90 * script.dir - 90;
    transform.eulerAngles = new Vector3(0,nerp,0);
    }
    }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Use code tags - it makes it easier to follow code, preserves spacing/etc, and shows line numbers.

    The problem is your declaration of "nerp". Local variables (variables inside a function) aren't private or public. So the compiler sees "private", assumes "oh we must be outside of the function now", and tells you it didn't find a } there because that's what should be between a function and outside of the function.
     
    Bunny83 likes this.
  3. RadioactiveChickenGames1

    RadioactiveChickenGames1

    Joined:
    Sep 29, 2020
    Posts:
    15
    Thank you very much! It worked and fixed all of my errors.:):)