Answer the question
In order to leave comments, you need to log in
I have this error in unity 2019.2.13f1?
I wrote a script, and when I want to run a coroutine, here is an error, (right after saving the robots appear)
Assets\Scripts\LuckyGame.cs(34,17): error CS0542: 'LuckyGame': member names cannot be the same as their enclosing type
Here is the script, please help if you can
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using System;
using UnityEngine.Monetization;
using UnityEngine.SceneManagement;
public class LuckyGame : MonoBehaviour
{
public int price;
public Text priceText;
public void StartGame()
{
if(Main.money > 4)
{
StartCoroutine(LuckyGame());
}
}
void Update()
{
priceText.text = price + "";
}
IEnumerator LuckyGame()
{
price = Random.Range(0, 11);
Main.money += price;
yield return new WaitForSeconds(0.5f);
price = 0;
}
}
Answer the question
In order to leave comments, you need to log in
at least google translate would translate the error message.
nothing confuses in these two lines?
IEnumerator LuckyGame()
public class LuckyGame : MonoBehaviour
and a class and method with the same name and in the error 'LuckyGame' is mentioned.
then try to guess how to fix it yourself))) it would be great.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question