Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on line 170,1 I have an error, CS1022

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

namespace RareCoders
{

    public class PlayerManager : MonoBehaviour
    {
        public InterAd interAd;
        int Count;

        #region Private Variables
        private float currentPosition;

        public float speed;

        public float maxSpeed = 5f;

        WaitForSeconds _waitTime;

        Coroutine speedCoroutine;

        Vector3 _scale;

        Vector3 _position;

        public UIController _uiController;

        public GameObject crashEffect;

        [SerializeField]
        Color[] bgColor;

        [SerializeField]
        float colorLerpDuration;

        Camera _cam;

        int randomColor;

        Color _FirstColor, _secondColor;

        bool lerpBG = false;

        float _time = 0f;
        #endregion
    }
    private void OnEnable()
    {
        _cam = Camera.main;
        //TheGlobals.playingMode = true;
        _waitTime = new WaitForSeconds(1f);
    }

    private void Update()
    {
        if (TheGlobals.playingMode)
        {
            DetectInput();

            if (lerpBG)
            {
                Color color = Color.Lerp(_FirstColor, _secondColor, _time);
                _time += Time.deltaTime / colorLerpDuration;
                _cam.backgroundColor = color;
                if (_time > colorLerpDuration)
                {
                    _time = 0;
                    lerpBG = false;
                    _FirstColor = _secondColor;
                }
            }
        }
    }

    // Update is called once per frame
    //void FixedUpdate()
    //{
    //    if (TheGlobals.playingMode)
    //    {
    //        currentPosition = transform.localPosition.y;
    //        currentPosition = currentPosition + Time.deltaTime * speed;
    //        transform.localPosition = new Vector3(transform.localPosition.x, currentPosition, transform.localPosition.z);
    //    }
    //}

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.layer == 8)
        {
            TheGlobals.sManager.allAudio[2].Play();
            crashEffect.transform.position = transform.position;
            crashEffect.SetActive(true);
            Camera.main.GetComponent<CameraShake>().ShakeCamera(0.4f);
            _uiController.GameOver();
            Destroy(this.gameObject);
            Count += 1;
            PlayerPrefs.SetInt("Dead_Count", Count);
            if (PlayerPrefs.GetInt("Dead_Count") == 3)
            {
                IntReclama.Show();
                PlayerPrefs.SetInt("Dead_Count", 0);
            }

        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == 9)
        {
            TheGlobals.sManager.allAudio[1].Play();
            collision.gameObject.SetActive(false);
            lerpBG = true;
            randomColor = Random.Range(0, bgColor.Length - 1);
            _secondColor = bgColor[randomColor];
        }
    }

    void DetectInput()
    {
        if (Input.GetMouseButtonDown(0))
        {
            InversePlayer();
        }
    }

    void InversePlayer()
    {
        _scale = transform.localScale;

        _position = transform.position;

        _scale.x = _scale.x * -1;

        _position.x = _position.x * -1;

        transform.localScale = _scale;

        transform.localPosition = _position;
    }

    public void SpeedIncrement()
    {
        speedCoroutine = StartCoroutine(speedManager());
    }

    public void StopIncrement()
    {
        StopCoroutine(speedCoroutine);
    }

    IEnumerator speedManager()
    {
        yield return _waitTime;

        if (speed < maxSpeed)
        {
            speed += 0.05f;
        }
        Debug.Log("Playing Mode " + TheGlobals.playingMode);

        if (TheGlobals.playingMode)
        {
            speedCoroutine = StartCoroutine(speedManager());
        }
    }
  } 
}


What I have tried:

I am new to coding so I don't know what to do
Posted
Updated 5-Feb-23 3:03am
v2
Comments
RedDk 5-Feb-23 14:10pm    
Get {professional help:
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs1022

You have an extra closing brace } in the following:
C#
} // <-- remove this closing brace
private void OnEnable()
 
Share this answer
 
v2
To add to what Richard says ...

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900