Click here to Skip to main content
15,662,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In Unity, I am on a project of 2D modelling.
So everytime I write a code, I encounter this problem.
I do not understand whether it is my fault or any tech related issue.

What I have tried:

I have restarted the whole console.
Changing scripts but still encountering it.
Updated 15-Jan-23 2:37am

It means exactly what it says: the class already has an object called the same thing: a method that has exactly the same name and parameters as the one you just created.

So look at the code you are getting the error on, and then look for another method with the same name and parameter list. One of them needs to be changed!
Share this answer
this is my code and i get the same problem do you have solutions?

using UnityEngine;

public class Invader : MonoBehaviour
public SpriteRenderer spriteRenderer { get; private set; }
public Sprite[] animationSprites = new Sprite[0];
public float animationTime = 1f;
public int animationFrame { get; private set; }
public int score = 10;
public System.Action<invader> killed;

private void Awake()
spriteRenderer = GetComponent<spriterenderer>();
spriteRenderer.sprite = animationSprites[0];

private void Start()
InvokeRepeating(nameof(AnimateSprite), animationTime, animationTime);

private void AnimateSprite()

// Loop back to the start if the animation frame exceeds the length
if (animationFrame >= animationSprites.Length) {
animationFrame = 0;

spriteRenderer.sprite = animationSprites[animationFrame];

Share this answer
Richard Deeming 16-Jan-23 5:49am    
Your question is not a "solution" to someone else's question.

If you want to ask a question, then ASK A QUESTION[^]. But you're going to have to provide a lot more information than you have here if you want anyone to be able to help you.

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