Hi Unity Community! I was using the Tanks Tutorial & C# Scripting. There is an error that pops up that says "error CS1513 : } expected." The Whole Script using UnityEngine; public class TankMovement : MonoBehaviour { public int m_PlayerNumber = 1; public float m_Speed = 12f; public float m_TurnSpeed = 180f; public AudioSource m_MovementAudio; public AudioClip m_EngineIdling; public AudioClip m_EngineDriving; public float m_PitchRange = 0.2f; private string m_MovementAxisName; private string m_TurnAxisName; private Rigidbody m_Rigidbody; private float m_MovementInputValue; private float m_TurnInputValue; private float m_OriginalPitch; private void Awake() { m_Rigidbody = GetComponent<Rigidbody>(); } private void OnEnable () { m_Rigidbody.isKinematic = false; m_MovementInputValue = 0f; m_TurnInputValue = 0f; } private void OnDisable () { m_Rigidbody.isKinematic = true; } private void Start() { m_MovementAxisName = "Vertical" + m_PlayerNumber; m_TurnAxisName = "Horizontal" + m_PlayerNumber; m_OriginalPitch = m_MovementAudio.pitch; } private void Update() { // Store the player's input and make sure the audio for the engine is playing. m_MovementInputValue = Input.GetAxis(m_MovementAxisName); m_TurnInputValue = Input.GetAxis(m_TurnAxisName); EngineAudio(); } private void EngineAudio() { // Play the correct audio clip based on whether or not the tank is moving and what audio is currently playing. if (Mathf.Abs(m_MovementInputValue) < 0.1f && Mathf.Abs(m_TurnInputValue) < 0.1f) { if (m_MovementAudio.clip == m_EngineDriving); } { m_MovementAudio.clip = m_EngineIdling; m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange); m_MovementAudio.Play(); } <THIS IS THE BRACKET else { if (m_MovementAudio.clip == m_EngineIdling); } { m_MovementAudio.clip = m_EngineDriving; m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange); m_MovementAudio.Play(); } } } private void FixedUpdate() { // Move and turn the tank. Move(); Turn(); } private void Move() { // Adjust the position of the tank based on the player's input. Vector3 movement = transform.forward * m_MovementInputValue * m_speed * Time.deltaTime; m_Rigidbody.MovePosition(m_Rigidbody.position + movement); } private void Turn() { // Adjust the rotation of the tank based on the player's input float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime; Quaternion turnRotation = Quaternion.Euler(0.f, turn, 0f); m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation); }
Please use code formatting. See the first post in this forum. I think your last three functions are not within the brackets of your class but it's hard to tell without proper formatting.
Thank you @Kurt-Dekker & @Antypodish I will check these out. If these don't help me I may get back to ya'll.
Your EngineAudio method has lots of problems. You have "if" statements with semicolons, and you have what appear to be reversed uses of curly braces. Use "{" to open and "}" to close, not the other way around. Also, post code using CODE tags so people can read it easier.
I have the brackets the right way around and the video that told me to do this the "if" statements are all correct 57:27
No. The syntax in the script is completely broken. Use a proper code editor, not notepad, and it will highlight the issues and help you correct them.
Your code: Code (CSharp): private void EngineAudio() { if (Mathf.Abs(m_MovementInputValue) < 0.1f && Mathf.Abs(m_TurnInputValue) < 0.1f) { if (m_MovementAudio.clip == m_EngineDriving); // Then what? } // What's the point of this scope? { m_MovementAudio.clip = m_EngineIdling; m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange); m_MovementAudio.Play(); } // An else that makes no sense else { if (m_MovementAudio.clip == m_EngineIdling); // Then what? A scope or command should follow a condition. } // Another pointless scope { m_MovementAudio.clip = m_EngineDriving; m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange); m_MovementAudio.Play(); } } // Orphaned curly brace } What I assume it should be: Code (CSharp): private void EngineAudio() { if (Mathf.Abs(m_MovementInputValue) < 0.1f && Mathf.Abs(m_TurnInputValue) < 0.1f) { if (m_MovementAudio.clip == m_EngineDriving) { m_MovementAudio.clip = m_EngineIdling; m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange); m_MovementAudio.Play(); } } else { if (m_MovementAudio.clip == m_EngineIdling) { m_MovementAudio.clip = m_EngineDriving; m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange); m_MovementAudio.Play(); } } } Have a look to see the differences between the two to learn how you messed it up.